in reply to Merging two hashes, keeping keys unique but adding values if necessary

Update: Just realized this is the very same as LanX above - DB<105> etc. was confusing me.

This may help, and will allow you to merge as many hashes as you wish:

use strict; use warnings; use Data::Dumper; my %hash1 = ( "key1" => 1, "key15" => 3, "key150" => 1 ); my %hash2 = ( "key1" => 1, "key15" => 1, "key140" => 1 ); my %merged; $merged{$_} += $hash1{$_} for keys %hash1; $merged{$_} += $hash2{$_} for keys %hash2; print Dumper(\%merged);
Output:
$VAR1 = { 'key15' => 4, 'key140' => 1, 'key1' => 2, 'key150' => 1 };