# the Apache checker is running forever while (1){ my $status # put here the right name of the Apche service open my $check, "sc query W32Time|" or die "unable to run the check.."; while (<$check>){ if ($_ =~ /STATUS\s+:\s(\d\s\w+)$/){ $status = $1; last; } } close $check; print scalar localtime(time), " Apache is in the state: ",$status,"\n"; unless ($status eq '4 RUNNING'){ print "Apache is not running! Trying a restart\n"; open my $start, 'NET START "W32Time"|' or die "Unable to attempt restart!"; print while <$start>; # add more actions: mail, event write... } sleep 60; # or another reasonable amount of time.. }