I was operating under the assumption that a user could enter "Kevin Johnson" and still get the value for $phnums{'kevin'} - i.e. more than what might be used as the explicit hash key. Possibly a poor assumption, but I couldn't think of a better reason for using regexen in the OP's code :-)
I recently ran across a hash setup as a dispatch table where most values were well defined, but some could match a variety - these were handled (in a generalized manner) like so:
if( exists $hash{$key} ){
&$hash{$key};
}
elsif( $key =~ /phrase/ ){
# several could match but all required the same action
&$hash{'some_action'};
}
else {
&$hash{'default_action'};
}
--chargrill
s**lil*; $*=join'',sort split q**; s;.*;grr; &&s+(.(.)).+$2$1+; $; =
qq-$_-;s,.*,ahc,;$,.=chop for split q,,,reverse;print for($,,$;,$*,$/)