perl -MDigest::MD5 -ne "print if ($seen{&Digest::MD5::md5_hex($_)}.= @ARGV) =~ /10$/" fileA.txt fileB.txt > output.txt #### use Tie::File; my @content; tie (@content, 'Tie::File', $file) or die "Error: couldn't tie $file: $!\n"; # .... and treat the filecontent like an array, e.g. print scalar(@content); # ..... untie (@content);