http://www.perlmonks.org?node_id=100571


in reply to socket reading...

You could put your socket into non-blocking mode and actually look at the return value from sysread. If your responses over the socket are record-oriented and terminated by a particular character (like, say, "\n") you could set $/ to that character and use the <$sock> form. Otherwise, if you have a length indication at the beginning of each response, read that first and then read exactly the right number of bytes.

update: corrected part about blocking if you try to read too many bytes.