use warnings; # Some Variables $pid = `pgrep -f '[a]bc'`; $msg = "Alive"; $timestamp = localtime(time); # Open file open $fh, '>>' , 'file.txt' or die ( "Could not open file! $!\n" ) ; # Loop Condition $i = 0; until ($i > 60) { if ($pid) { $timestamp = localtime(time); print $fh ("$pid , $timestamp , $msg\n"); $pid = `pgrep -f '[a]bc'`; }else{ $timestamp = localtime(time); print $fh ("No pid , $timestamp\n"); $pid = `pgrep -f '[a]bc'`; } $i = $i +1; sleep 10; } print $fh ("Time over , $timestamp\n"); close $fh; #### example: 9910 abc , Tue Sep 13 04:44:33 2016 , Alive