in reply to improve performance

You can transform @arraytocompare to a hash as you can see below. Hash key lookup is very effective.
my $hashtocompare{$_}++ for (@arraytocompare); foreach my $strfile (@tempfiles) { push @newarray, $strfile unless exists $hashtocompare{$strfile}; }