use Win32::OLE; # 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'; } # hide/show the document $word->{Visible} = 0; # Create new document my $d = $word->Documents->Add; # define selection my $s = $word->Selection; #set lines to be written to document my @lines = ( "This is a test line\n", "This is second test Line\n", "This is the third line\n", ); # add the lines of text $s->TypeText($_) for @lines; # save our object $word->WordBasic->FileSaveAs("c:\\test.doc"); # undef our object out of existance undef $word;