my $path = "/tmp/testpatch"; opendir DIR, $path or die $!; my @tempfiles = readdir DIR; #this array has list of all the files, previously processed and newly added (8000 files) closedir DIR; foreach my $strfile (@tempfiles) { if (!grep /$strfile/, @arraytocompare) #This array has list of files which were processed in the passed { push (@newarray, $strfile); # in this array i get all the new files which i need to process now. } }