foreach my $key (keys %B) { if (exists $A{$key}) { # do something next; } $A{$key} = $B{$key}; }