foreach $host (@hosts) { pipe($fhr{$host}, $fhw{$host}); if (fork() == 0) { # child process spawned #do stuff and then write to pipe like this: close $fhr{$host}; print { $fhw{$host} } "$mystr"; close $fhw{$host}; } } while (wait() != -1) { #wait for children to finish } foreach $host (@hosts) { close $fhw{$host}; chomp ($mystring=<$fhr{$host}>); close $fhr{$host}; print "DATA from $host: $mystring"; }