while ($sock->recv($msg, 1024)) { $msg1 = substr $msg, 0, -1; print "MESSAGE: $msg1 LENGTH: $length"; }