while ( my ($key, $value) = each(%hash1) ) { $hash2{ $key } = $value if $key =~ /regex/; }