in reply to Read the two files

If you have big files, don't slurp them in in one big chunk. Instead of

@datas=<DAT>; foreach ...

use

while ($data= <DAT>) {

The usual method to compare two files in perl is to read one file into a hash and then read the other file line by line and check if that line is in the hash

If the hash gets too big to fit into memory (very likely in your case), a module like DBM::Deep will store your hash transparently into a file