my $sel = new IO::Select; $sel->add($sock); while (1) { if ($sel->can_read(1)) { # 1 second timeout # do read, appending to buffer sysread($sock, $buf, 1024, length($buf)); # check for a complete line, process command, etc. } last if ($die); }