use File::Spec; # define variables as above opendir(CURRDIR, $mypath) or die "Can't open $mypath: $!"; my @files = map { File::Spec->catfile($mypath, $_) } grep { /^[\d\w\s]+\.$filetype/ } readdir CURRDIR; foreach my $file (@files) { # reveal potentially nasty leading/trailing whitespace print "Processing ->$file<-\n"; my $book = $Excel->Workbooks->Open($file) or die "Error opening $file: $!"; $book->Close(); }