my @intersection = grep { exists $hash2{$_} } keys %hash1; my %intersection; @intersection{ @intersection } = @hash1{ @intersection };