You might want to use sysread instead of my $data = <$fh>. See sysread and syswrite in tcp sockets
# as a start change
my $line = <$fh>;
sysread $fh, my $line, 1024;,
The basic issue is that <$fh> does a buffered read from the socket. It won't return from the read call until $/ (defaults to "\n") is encountered on the channel.
IO::Select::can_read just means that there is data on the channel, it does not necessarily mean that there is a full record (defined as: a chunk terminated with an occurence of $/) waiting on the channel.