in reply to reading lines from sockets with while

If you want to avoid blocking on a read, try reading up on IO::Select. This module wraps around the select() socket API, basically letting you know when a handle may be read from (has data waiting to be read) or written to.

See Using socket descriptor with IO::Select for a detailed explanation.

dmm

If you GIVE a man a fish you feed him for a day
But,
TEACH him to fish and you feed him for a lifetime