# this hash has list (keys) of all the files previously processed my %processed = map { $_ => 1 } @arraytocompare; my $path = "/tmp/testpatch"; opendir DIR, $path or die $!; # in this array i get all the new files which i need to process now my @newarray = map { ! exists $processed{$_} ? $_ : () } readdir DIR; closedir DIR;