use strict; use warnings; use Tk; my @unpaidbills = (['Fred', 1.27], ['Joe', 3.46], ['Francis', 2.22], ['Joanne', 5.23]); my @checkboxes; my $main = new MainWindow; foreach my $bill (@unpaidbills) { my $state = 0; # Note we get a new $state each time through my $button = $main->Checkbutton ( -text => "$bill->[0]: $bill->[1]", -variable => \$state ); $button->pack (); $checkboxes[@checkboxes] = [$button, $bill, \$state]; } $main->Button(-text=>'Submit', -command=> [\&doSubmit, \@checkboxes])->pack (); MainLoop (); sub doSubmit { my ($checkboxes) = @_; for my $entry (@$checkboxes) { my ($button, $bill, $state) = @$entry; if ($$state) { print "$bill->[0] paid \$$bill->[1]\n"; } else { print "\$$bill->[1] not paid for $bill->[0]\n"; } } }