foreach my $id(@ID){ print "$id\n" if grep(/^$id$/, @files); }