my %hash1 = (a=>4,b=>5,c=>6,d=>7); my %hash2 = (a=>4,b=>5,c=>6,e=>7); # make a temp. copy of the keys of %hash1 my %h1k = map {$_=>1} keys %hash1; # delete from it all the keys present in %hash2 delete @h1k{keys %hash2}; # you're left with the keys that are only in %hash1 print "hash1 only: $_\n" for keys %h1k; # and vice versa for %hash2: my %h2k = map {$_=>1} keys %hash2; delete @h2k{keys %hash1}; print "hash2 only: $_\n" for keys %h2k; __END__ hash1 only: d hash2 only: e #### my %hash1 = (a=>4,b=>5,c=>6,d=>7); my %hash2 = (a=>4,b=>5,c=>6,e=>7); { delete local @hash1{keys %hash2}; print "hash1 only: $_\n" for keys %hash1; } { delete local @hash2{keys %hash1}; print "hash2 only: $_\n" for keys %hash2; } # %hash1 and %hash2 are unchanged here __END__ hash1 only: d hash2 only: e #### my %hash1 = (a=>4,b=>5,c=>6,d=>7); my %hash2 = (a=>4,b=>5,c=>6,e=>7); # make a temp. copy of the keys of %hash1 my @h1k = keys %hash1; # delete from %hash1 all the keys in %hash2 delete @hash1{keys %hash2}; # hash1 only has keys left that are unique to it print "hash1 only: $_\n" for keys %hash1; # delete from %hash2 all the keys from %hash1 delete @hash2{@h1k}; # you're left with the keys that are only in %hash2 print "hash2 only: $_\n" for keys %hash2; __END__ hash1 only: d hash2 only: e