in reply to When do I stop reading?

if you're creating both the client and the server application, you could send some sort of end character/string to tell someone that the string has ended.

otherwise, each command you send a TCP server will get some set response. depending on the command and whether the server responds with an error or not, you will recieve a standard type of reply. its just a matter of knowing when the reply has ended.

as for the byte disparity, that could be a problem with perl implicitly stripping certain characters from input.

hope this helps. if not, let me know a little more about what you're trying to do... commands and etc.