if ($fh == $ircsock) { ... if (sysread($ircsock, $ircdata, 512)) { ... } else { $sel->remove($ircsock); close($ircsock); ...reopen $ircsock... ...add $ircsock to $sel... } #### 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... } }