sub foo { my $s = shift; if( $s =~ /^(AAA|BBB|CCC)$/ ){ my $foo = $HASH{$1}; my $bar = bar($s); ... } }