my $runningprocesses; foreach $element (@data) { ++$runningprocesses if my $pid = fork(); if ($pid == 0) { # in child process system("rsh $computers[$runningprocesses % 10] 'analyse @$element'"); exit; } } while ($runningprocesses > 0) { wait; # wait for all the children to return --$runningprocesses; }