while ($more_childs_to_produce) { $pid= open($child[$childnumber++], "-|"); if ($pid) { # parent # here we have another "file" # to read frome with <$child[$childnumber-1]> } else { # child # Do the child's work and exit; } }