Process File A contents and store in %hash_one while() { # do whatever you need to to compute $key if (! exists $hash_one{$key}) { print "File B contains $key but File A does not\n"; } delete $hash_one{$key}; } # the keys left in %hash_one weren't in File B foreach(keys %hash_one) { print "File A contains $key, but File B does not\n"; }