# 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; #### # this hash has list (keys) of all the files previously processed my %processed = map { $_ => 1 } 100001 .. 108000; # in this array i get all the new files which i need to process now my @newarray = map { ! exists $processed{$_} ? $_ : () } 108001 .. 116000; print scalar @newarray, "\n";