sub KillWinWord { print "Closing Application... -> "; my $flag = 0; @temp = `tasklist.exe /FI "STATUS eq running"`; foreach $temp (@temp) { if ($temp =~ WINWORD) { $flag = 1; } } if ($flag == 1) { $t = `taskkill /IM "WINWORD.EXE"`; print "$t"; } else { print "WORD handle is closed..."; } print "\n\n"; } #### foreach $key (sort (keys(%SReport_Hash))) { # Lets get first Name out from the key $key =~ s/\\\\//g; @key_value_chunks = split(/\\/,$key); $SReport_Name = $key_value_chunks[5]; open WordDocHandleCountry1, ">> $SReport_Country1"; open WordDocHandleATLCountry2, ">> $SReport_Country2"; $key = '\\\\' . $key; # Changing $key to real path &Read_Document($key, \*WordDocHandleCountry1, \*WordDocHandleCountry2, $SReport_Name, 1); &KillWinWord(); }