# A version that also checks for lines in file2 that are not in file1: open(FILE1, ' 1 } ; %file2 = map { $_ => 1 } ; foreach (keys(%file1)) { if ($file2{$_}) { print("Found in both files: $_"); } else { print("Found only in first file: $_"); } } foreach (keys(%file2)) { unless ($file1{$_}) { print("Found only in second file: $_"); } }