but $sockbr is only zero at end of file...

all blank lines you encounter still have the $crlf chars so the length of those is 2 (I tested it with a smaller text file)