use IO::Select qw( ); use IO::Handle qw( ); pipe(my $rfh, my $wfh) or die; $wfh->autoflush(1); if (fork()) { my $sel = IO::Select->new($rfh); while ($sel->can_read()) { my $got = <$rfh>; last if !defined($got); chomp $got; print("It took ", (time()-$got), " seconds to get the msg\n"); } } else { for (;;) { print($wfh time(), "\n") or die; print($wfh time(), "\n") or die; sleep(3); } } #### It took 0 seconds to get the msg It took 3 seconds to get the msg It took 0 seconds to get the msg It took 3 seconds to get the msg It took 0 seconds to get the msg ... #### my $sel = IO::Select->new($rfh); my $buf = ''; while ($sel->can_read()) { sysread($rfh, $buf, 64*1024, length($buf)) or last; while ($buf =~ s/^(.*)\n//) { my $got = $1; print("It took ", (time()-$got), " seconds to get the msg\n"); } } #### It took 0 seconds to get the msg It took 0 seconds to get the msg It took 0 seconds to get the msg It took 0 seconds to get the msg It took 0 seconds to get the msg It took 0 seconds to get the msg ...