... my @handles = map { open my $fh, '<', $_; $fh } @files; for my $index (0 .. $#files) { next unless $handles[$index]->opened(); while (<$handles[$index]>) { if (/a particular pattern/) { print "Pattern found in $files[$index]\n"; last; } } } close $_ for grep { $_->opened() } @handles; ...