my $clientdata = ""; while (1) { #-- Add the new data at the end of the existing one sysread $fh, $clientdata, 512, length $ircdata; #-- See if we have a full line we can process while ($fh =~ s/^(.*?)\r?\n//) { my $line = $1; ... do your per-line regex stuff here... } }