in reply to compare two files

If the files are sorted, your quickest option will probably be to take the first line from each file, print the line from file1 if they're different or advance a line in file2 if they're the same, and then advance a line in file1. This is also very space-efficient, since you only need to have one line from each file in memory at a time.

A basic implementation of this would be:

#!/usr/bin/perl -w use strict; open FILE1, '<', 'file1' || die "Can't open file1: $!"; open FILE2, '<', 'file2' || die "Can't open file2: $!"; my $line1 = <FILE1>; my $line2 = <FILE2>; while ($line1 && $line2) { if ($line1 == $line2) { $line1 = <FILE1>; $line2 = <FILE2>; } else { print $line1; $line1 = <FILE1>; } } print $line1 if defined $line1; while ($line1 = <FILE1>) { print $line1; }
Note that this implementation assumes that there are no values in file2 which are not also present in file1 and that neither file contains any duplicates.

If the files are not sorted (and you're not going to be using them repeatedly), then a hash-based solution such as others have proposed would probably be faster than sorting them and using this method.