my $select = IO::Select->new(); $select->add(fileno $child_reader); $last_heartbeat_sent = gmtime(0); my $buf = ''; PROCESS: while (1) { my @ready = $select->can_read(5); if (scalar(@ready)) { my $read = sysread($child_reader, $buf, 64*1024, length($buf)); if (!defined($read)) { warn "Failed read on pipe to parent - $!"; last PROCESS; } elsif ($read == 0) { # EOF warn "EOF on pipe to parent"; last PROCESS; } else { while ($buf =~ s/^(.*)\r\n//) { send_message($1); # send msg down socket to server } } } else { my $now = gmtime; if (($now - $last_heartbeat_sent) > 25) { send_message("\r\n"); $last_heartbeat_sent = $now; } } }