use IO::Handle; my $fh = *STDIN; $fh->blocking(0); while (1) { # this block would go in your callback, not in a loop like this: $fh->sysread( my $data, 255 ); print "$data"; # split $data into lines on CR|LF put the first line on the end of the last line of the previous block (use an array perhaps) }