in reply to grep for hash?

This is such a frequently reinvented wheel! 8)

IMHO something like hgrep() or hmap() should be somewhere in the core-moduls... with a code-prototype it's easy to accomplish.

Anyway TIMTOWTDI:

Without explicit grep

%hash_2= map { /regex/ ? ( $_ , $hash_1{$_} ) : () } keys %hash_1;

Hashslice:

my @keys = grep { /regex/ } keys %hash_1; @hash_2{@keys} = @hash_1{@keys};

http://www.perl-community.de/bat/poard/message/120873

Cheers Rolf