# put this before the if mentioned above my $pull_downs = join "", $pull_down1, $pull_down2, $pull_down3, $pull_down4; # or, if you're using CGI.pm, something like this: my $pull_down = join "", map { $query->param("pull_down$_") } 1 .. 4; # (whatever works; just mash them together. $pull_downs now looks like your binary numbers. # And this returns true only if the number is one of your valid ones: { my $valid = qr/^(0000|1000|1010|1100|1111)$/; sub valid_state { return shift =~ $valid; | }