my $hashtocompare{$_}++ for (@arraytocompare); foreach my $strfile (@tempfiles) { push @newarray, $strfile unless exists $hashtocompare{$strfile}; }