my $path = "C:/Perl/bin/Anti"; opendir( DIR, $path ) or die "opendir failed on $path: $!\n"; my @files = grep {-f "$path/$file"} readdir DIR; ### updated as per bluto's comment below closedir DIR; for my $file ( @files ) { open( MYFILE, "<", "$path/$file" ) or do { warn "open failed on $path/$file: $! -- moving on...\n"; next; }; while () { ... } }