Returning a new value instead of mutating the sub arguments: sub combine_values { my $old = shift; my $new = shift; return map {$_ => { %{ $old->{$_} }, %{ $new->{$_} || {} } }} keys %$old; } Ran