use strict; use warnings; use Carp; use Data::Dumper; use English '-no_match_vars'; use FileHandle; $| = 1; my $no_of_childs = 3; my @fh; my $index = 0; while ($index < $no_of_childs) { print "PID $PID\n"; my $pid; $fh[$index]{'fh'} = new FileHandle; $fh[$index]{'fh'}->autoflush(1); $pid = $fh[$index]{'fh'}->open("|-"); if ($pid) { # parent $fh[$index]{'pid'} = $pid; print "parent pid $PID creating child " . $index++ . "\n"; } else { # child print "child pid $PID creating child " . $index++ . "\n"; while (1) { # Here we will do the child work, and read input from STDIN print "$PID checking for input\n"; my $line = ; if ($line) { print "$PID got something from father !!! $line\n"; } sleep 1; } exit; } } print Dumper \@fh; my $fh; sleep 5; $fh = $fh[0]{'fh'}; print "send hi to child 1\n"; print $fh "shalom yeled 1"; sleep 2; $fh = $fh[1]{'fh'}; print "send hi to child 2\n"; print $fh "shalom yeled 2"; sleep 2; $fh = $fh[2]{'fh'}; print "send hi to child 3\n"; print $fh "shalom yeled 3";