$library = [contents of library.txt] $input = [contents of input.txt] my %in_library = (); foreach $entry (split(/\n/, $library)) { $in_library{"$entry"} = 1; } my @input = split(/\n/, $input); foreach $entry (@input) { if ($in_library{"$entry"}) { print "found - $entry\n"; } else { print "new - $entry\n"; } }