$matching_key=grep { $_ =~ /$regex/ } keys %tax2loc; #### @all_matching_keys = grep { $_ =~ /$regex/ } keys %tax2loc; $matching_key = $all_matching_keys[0]; #### ($matching_key) = grep { $_ =~ /$regex/ } keys %tax2loc; #### $matching_key = first { $_ =~ /$regex/ } keys %tax2loc; #### $matching_key = first { /$regex/ } keys %tax2loc;