for($forkcount = 0; $forkcount < $maxfork; $forkcount++) { sleep 1; # so we don't overload ourselves if (my $pid = fork) { # parent process, do nothing } elsif(defined $pid) { # child process, do stuff print "> doing thing\n"; sub_to_do(); print "new child: number $forkcount\n"; exit 0; } else { print STDERR "!! hit process limit\n"; } while (1) { sleep 1; }