$g=10; $|=1; for ($i=0; $i<$g; $i++) { pipe ($rh, $wh); # both of these are generated in the loop if ($pid[$i]=fork()) { # parent process waitpid($pid[$i], 0); # wait for child close ($wh); while (<$rh>) { # gimme the output if ($_ =~ m/^Error/) { push (@error, $_); } elsif ($_ =~ m/^Hits/) { push (@hits, $_); } else { push (@data, $_); } # each is a result from an engine } } else { close ($rh); open (STDOUT, ">&$wh"); $|=1; print "I will wait for ",$i+2," seconds\n"; sleep $i+1; print "Good morning. I slept about ",$i+2," seconds\n"; exit(0); } } print @data;