#!/usr/bin/perl use strict; use warnings; use IO::Pipe; use IO::Handle; use IO::Select; my $pipe = IO::Pipe->new(); my $pid = fork(); die "failed to fork: $!" unless defined $pid; if ($pid) { $pipe->reader(); my $select = IO::Select->new(); $select->add($pipe); while (1) { my @ready = $select->can_read(1); foreach my $h (@ready) { my $line = <$h>; chomp $line; print "PARENT sees <$line>\n"; } } } else { $pipe->writer(); $pipe->autoflush(1); my $c = 0; while (1) { $c++; print "CHILD writing <$c>\n"; $pipe->print("$c\n"); sleep 1 unless $c % 5; # pause after each fifth line } }