my %input= $cgi->Vars(); foreach $name (keys %input){ $value = $input{$name}; } #now test for conditions if ((-e $input{"whatever") && (-e $input{"wherever") ) { your subroutine goes here } # I may have missed some details involving autovification of hash keys, # and grepping the %input hash keys may be better, but right now, # I'm not sure of the cleverest way to grep an array for 2 values. # I leave that to you, or a more clever monk than me.