in reply to Merge hash into another hash

To preserve the key->{value} structure of the hash, I had to create a recursive function. This works for me:
sub merge_hashes { my ($x, $y) = @_; foreach my $k (keys %$y) { if (!defined($x->{$k})) { $x->{$k} = $y->{$k}; } else { $x->{$k} = merge_hashes($x->{$k}, $y->{$k}); } } return $x; }