foreach (keys %hash1){ $intersected_hash{$_} = $hash1{$_} if exists $hash2{$_}; }