# This version adds difference counts: open(FILE1, '); $file2{$_}++ while (); foreach (keys(%file1)) { if ($file2{$_}) { $diff = $file2{$_} - $file1{$_}; if ($diff) { if ($diff < 0) { print("Found in first file $diff times more than in second file: $_"); } else { print("Found in second file $diff times more than in first file: $_"); } } else { print("Found in both files an equal number of times: $_"); } } else { print("Found only in first file ($file1{$_} times): $_"); } } foreach (keys(%file2)) { unless ($file1{$_}) { print("Found only in second file ($file2{$_} times): $_"); } }