use strict; use Data::Dumper; %muthash = ( key1 => '1', key15 => '3', key150 => '1', ); %copyhash =( key1 => '1', key15 => '1', key140 => '1', ); %mergedhash = (); %mergedhash = map {$_=> $muthash{$_} + $copyhash{$_}; } (keys %muthash, keys %copyhash); print Dumper(\%mergedhash); #### my %muthash = ( "key1" => 1, "key15" => 3, "key150" => 1 ); my %copyhash = ( "key1" => 1, "key15" => 1, "key140" => 1 ); my %mergedhash; foreach (keys %muthash){ $mergedhash{$_} = $muthash{$_}+ $copyhash{$_}; } foreach (keys %copyhash){ $mergedhash{$_} = $muthash{$_}+ $copyhash{$_} unless defined $mergedhash{$_}; } print Dumper(\%mergedhash);