foreach (@contentsOfDataBase){ chomp ($_); print "$_"; @inDirectoryNotInDataBase = grep {!"$_"} @contentsOfDirectory; print "@inDirectoryNotInDataBase", "\n"; } foreach (@copyOfContentsOfDirectory){ print "$_"; @pdfNoMatchingDirectory = grep (!$_, @contentsOfDataBase);#for current element in @copyOfContentsOfDirectory find all elements of @contentsOfDataBase that are not a match print "@pdfNoMatchingDirectory", "\n"; }