use strict; use warnings; use IO::Select; use IO::Socket; my $child = my $parent = my $pid = undef; # Create a socket pair for IPC (both ways) socketpair($child, $parent, AF_UNIX, SOCK_STREAM, PF_UNSPEC); $child->autoflush(1); $parent->autoflush(1); if (!defined($pid = fork())) { die $!; } elsif ($pid == 0) { close($child); print $parent "LINE1\nLINE2\n"; sleep(5); close($parent); exit 0; } else { close($parent); # Make sure the client has already started and sent the two lines sleep(2); my $ios = IO::Select->new($child); while (my @handles = $ios->can_read(0)) { foreach my $handle (@handles) { my $message = <$handle>; print "Read message: ".$message; } } close($child); }