#!/usr/bin/perl use strict; use FileHandle; use Data::Dumper; my $childs = { A => { pid => undef, handler => undef, blabla => () }, B => { pid => undef, handler => undef, blabla => () }, C => { pid => undef, handler => undef, blabla => () } }; foreach my $name ( keys %{$childs} ) { $childs->{ $name }->{ handler } = new FileHandle; $childs->{ $name }->{ pid } = $childs->{ $name }->{ handler }->open( "-|" ); if ($childs->{ $name }->{ pid }) { # The child's talking... while(my $line = $childs->{ $name }->{ handler }->getline()) { push @{$childs->{ $name }->{ blabla }}, $line; } } else { # Childs' STDOUTs are read by the parent print "Hi! I'm $name and I'm good!"; exit; } } print Dumper( $childs );