use Win32::OLE; use Win32::OLE::Const 'Microsoft Word'; my $dir = "C:"; my $ext = "wps"; my @files = map{ s!/!\\!g; $_ } grep{ m/\.($ext)/ } glob( "$dir/*" ); # check if Word exists and is running my $word = Win32::OLE->GetActiveObject('Word.Application'); die "Word not Installed" if $@; # start Word program instance if required or die if unable to unless (defined $word) { $word = Win32::OLE->new('Word.Application', sub { $_[0]->Quit; } ) or die 'Cannot start Word'; } $word->{Visible} = 0; # set to 1 to watch for my $infile( @files ) { my $doc = $word->{Documents}->Open($infile) or die "Can't open $infile, Reason:$Win32::OLE::LastError"; (my $outfile = $infile ) =~ s/\.\w+$/.doc/; # change file extension to .doc $doc->SaveAs( { FileName => $outfile, FileFormat => wdFormatDocument } ); $doc->Close; undef $doc; } $word->Close; undef $word;