foreach my $file ( grep { -f "$path/$_" } @files ) { open( my $fh, '<', "$path/$file" ) or die "Unable to open '$file': $!\n"; while( <$fh> ) { # process each line here. } }