my $length; while (defined($length=sysread($socket, my $buffer, 65536)) && $length != 0) { ... } die "sysread: $!" if (!defined($length));