use Event; use IO::File; my $f = IO::File->new('for t in 1 2 3 4;do echo one $t; sleep 4;done; |'); my $g = IO::File->new('for t in 1 2 3 4;do echo two $t; sleep 4;done; |'); my $h = IO::File->new('for t in 1 2 3 4;do echo three $t; sleep 4;done; |'); my (@f,@g,@h); my $done; sub newIO { my ($f,$fr) = @_; Event->io( fd => $f, poll => 're', cb => sub { my $e = $_[0]; my $w = $e->w; my $fd = $w->fd; if ($fd->eof) { $pending--; $w->cancel; return; } my $line = <$fd>; push @{$fr}, $line; }, ); $pending++; } Event->idle( min => 1, max => 2, cb => sub { print "last one: $f[-1]"; print "last two: $g[-1]"; print "last three: $h[-1]"; Event::unloop if ($pending == 0); }, ); newIO($f,\@f); newIO($g,\@g); newIO($h,\@h); Event::loop; print @f; print @g; print @h;