#!/usr/bin/perl
use Win32::OLE;
use Win32::OLE::Const 'Microsoft Office';
# Get the current running Microsoft Word applications
my $word = Win32::OLE->GetActiveObject('Word.Application') || Win32::OLE->new('Word.Application', 'Quit');
# Get all open Word documents
my $documents = $word->Documents;
# Close each open document
foreach my $document ($documents) {
$document->Close;
}
# Quit the Word application
$word->Quit;