I've tried it on my system, and it gets inside the while loop only when a newline character is send to the server. $client->can_read returns only when a newline character is received. I tried telnet and netcat as clients. It turns out the problem is not with sysread or recv but can_read. Thanks.