Red
Yellow
Brown
Green
Blue
Pink
Black
#!/usr/local/bin/perl -w

use strict;
use CGI;
use CGI::Carp qw(fatalsToBrowser);
use Template;
use File::Slurp;

my $cgi = CGI->new;

# print the text/html header
print $cgi->header;

# the candidate colours
my @boxes    = qw(Red Yellow Brown Green Blue Pink Black);

# the colours selected from the last time
my @selected = $cgi->param('colours');


my %params = (
    boxes    => [@boxes],
    selected => [@selected],
    script   => join("",read_file($0)), # this script
);

my $template = Template->new;
$template->process(\*DATA, \%params) || die $template->error;

__DATA__
<html>
<head>
    <title>Checkbox test</title>
</head>
<body>
    [% FOREACH col IN selected -%]<font color="[% col %]">[% col %]</font>[% ', ' UNLESS loop.last %][% END %]<br />
    <form>
    [% FOREACH box = boxes %]
        <input type="checkbox" name="colours" value="[% box %]" [% IF selected.grep(box).size ;"checked"; END; %]/> [% box %]<br />
    [% END %]
    <input type="submit" value="Submit!" />
    </form>
    <pre>
[% script | html %]
    </pre>
</body>
</html>