use warnings; use strict; my $children= 2; # How many to fork my @out; my $first_child; $|=1; # unbuffered output to see the effect my $pid= open($first_child, '-|'); if ($pid) { # parent: Collects all output @out= <$first_child>; } else { # child forks again and produces output my(@child, @childpid); for (my $i=0; $i<$children; ++$i) { $childpid[$i]= open($child[$i], '|-'); if ($childpid[$i]) { # parent # does nothing yet } else { # child produces some output my $j=10; while ($j--) { print "I'm child $i and will tell this $j more time(s)\n"; sleep 1; } exit; } } foreach (@child) { # closing all child handles close $_; } exit; } print @out;