#!/usr/bin/perl use warnings; use strict; #### my @kids = ( sub { print "First!", $/; }, sub { print "Second!", $/; }, sub { print "Third!", $/; }, ); pipe my ($in, $out); #### my %kid; for (@kids) { my $cpid = fork; defined $cpid or warn("Couldn't fork"), next; $cpid or do { # child close $in or die $!; select $out; $| = 1; $_->(); exit 0; }; $kid{$cpid} = undef; } #### close $out or warn $!; s/.$/??? says the child/, print while <$in>; delete $kid{+wait} while %kid;