my $counter = 0; my $start; my $end; while () { $counter++ if /send/i; $start = time if($counter == 1); if($counter == 3){ $counter = 0; $end = time; system("shellscript.sh &") if(($end - $start) > 3); } }