my $max_tasks=3; my $pid=fork(); if ($t_counter >= $max_tasks) { waitpid(-1,0); } $t_counter++; ...