in reply to Comparison between keys in hash

Are you really counting words with a shell command? Check this out:

my $string="It is a guide to action which ensures that the military al +ways obey the commands of the party"; my %counts; foreach (split(' ',$string)) { $counts{$_}++; } foreach (keys %counts) { print "Word '$_' occurs $counts{$_} times\n"; }

will print

Word 'the' occurs 3 times Word 'It' occurs 1 times Word 'a' occurs 1 times Word 'of' occurs 1 times Word 'ensures' occurs 1 times Word 'which' occurs 1 times Word 'commands' occurs 1 times Word 'that' occurs 1 times Word 'is' occurs 1 times Word 'to' occurs 1 times Word 'always' occurs 1 times Word 'military' occurs 1 times Word 'guide' occurs 1 times Word 'party' occurs 1 times Word 'action' occurs 1 times Word 'obey' occurs 1 times

Oh, and the problem you were asking about: Just use foreach (key ...) on one hash and compare with the second hash. Then do the same with the second hash but only look at keys not in the first hash (as they are the only ones not handled by the first foreach loop).