#!/usr/local/bin/perl use strict; use warnings; sub child { my( $child ) = @_; if( fork == 0 ) { # Child close WRITER; select STDOUT; $| = 1; select READER; $| = 1; while( 1 ) { my $line = ; print STDOUT "$child: $line"; sleep 1; } } return; } pipe( READER, WRITER ) or die "Can't open pipe: $!"; # Create children child( 'a' ); child( 'b' ); child( 'c' ); child( 'd' ); child( 'e' ); # Parent close READER; select WRITER; $| = 1; my $str = ""; foreach ( 0..50 ) { $str .= "$_\n"; } while( 1 ) { print WRITER $str; }