use strict; use warnings; use Win32::OLE; use Win32::OLE::Const 'Microsoft Word'; use Cwd; my ($file) = @ARGV; my $cwd_path = getcwd(); $cwd_path=~ s/\//\\/gs; my $file_name = "$cwd_path\\$file"; my $Word = Win32::OLE->new('Word.Application'); $Word->{'Visible'} = 1; $Word->Documents->Open($file_name) || die("Unable to open document", Win32::OLE->LastError());; $Word->Selection->HomeKey (wdStory); $Word->Selection->Text="This is the inserted text"; $Word->Selection->Collapse (wdCollapseEnd); $Word->Selection->TypeParagraph; $Word->Selection->Text("This is the inserted text 2"); $Word->Selection->Collapse (wdCollapseEnd); $Word->Selection->TypeParagraph; $Word->Documents($file_name)->Save(); $Word->Quit();