use Win32::OLE qw(in with); use Win32::OLE::Const 'Microsoft Excel'; $Win32::OLE::Warn = 3; my $mypath = 'c:\perl\projects'; my $elem = ""; my $filetype = "xls"; my @files; if (opendir CURRDIR, $mypath){ @allfiles = readdir CURRDIR; closedir CURRDIR; } for my $elem (0..$#allfiles){ if ($allfiles[$elem] =~ /^[\d\w\s]+\.$filetype/) { $cfile = "$mypath\\$allfiles[$elem]"; push (@files,$cfile); } } my $Excel = Win32::OLE->GetActiveObject('Excel.Application') || Win32::OLE->new('Excel.Application', 'Quit'); # @files = ('c:\perl\projects\letterdist.xls', 'c:\perl\projects\freqs.xls'; #Use this instead of above regex, below works fine for my $x (0..$#files){ printf "%-s\n",$files[$x]; my $Book = $Excel->Workbooks->Open($files[$x]) || die " $! "; # open Excel files #my $Book = $Excel->Workbooks->Open('c:\perl\projects\LetterDist.xls') || die " $! "; # open Excel files #This works fine $Book->Close(); }