use strict; use Data::Dumper; my %hash1 = qw/ A 1 B 2 /; my %hash2 = qw/ C 3 D 4 /; mergetwohashes(\%hash1, \%hash2); print Dumper(\%hash1); sub mergetwohashes { my ($a, $b) = @_; $a->{$_} = $b->{$_} foreach keys %$b; }