my @nums = (1..6); my (@menu, %option, $selected); foreach $x (@nums) { # Set selected to true if the state equals the current item. if ($state eq $x) { $selected = 1; } else { $selected = 0; } # Tell the option the item value and whether it's selected. my %option = { item => $x, selected => $selected }; # Put the option in the menu. push @menu, \%option; } # Send the menu to the template; $t->param( menu => \@menu );