use Data::Dumper; use strict; my $h1 = {"a" => 1, "b" => 2}; my $h2 = {"c" => 1, "b" => 3}; my $ret = plus($h1, $h2); print Dumper($ret); sub plus { my $ret = {}; my ($hash1, $hash2) = @_; for (keys %$hash1) { if (exists($hash2->{$_})) { $ret->{$_} = $hash1->{$_} + $hash2->{$_}; } else { $ret->{$_} = $hash1->{$_}; } } return $ret; }