$file = 'C:/Users/Siddharth/Desktop/file1.txt'; open(FH, $file) or die("File $file not found"); open(F2,"C:/Users/Siddharth/Desktop/file2.txt"); @a1=; foreach $a1(@a1){ while(@a2 = ) { if( grep $a2 =~ /$_/,$a1) { } else { print "$a1\n"; } } }