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"; }