in reply to about read HTTP header.

You may also want to look at the select() call, which will let you know when there is input on a filehandle, how much, and will also handle the wait as well.
$my_handle = "";
vec ($my_handle, fileno($httpsocket), 1) = 1;
$timeout = 0.5; # half-second

$nfound = select($test_handle=$my_handle, undef, undef, $timeout);
if (vec($test_handle, fileno($httpsocket),1)) {
    sysread($hhtpsocket, $buffer, $nfound);
}
This uses a lot of messy bitmasks, but you'll need to do it this way if you're using standard filehandles. If you're using IO::Socket, you can instead use IO::Select, which handles all the ick under the covers:
use IO::Select;

$select = IO::Select->new();
$select->add($httpsocket);  # and as many more as you like

$timeout =  0.5;
@read_from = $select->can_read($timeout);
foreach my $socket (@read_from) {
   # Read the socket
}
It seems that there's no simple call to get the length, though. Again, as takshaka says, if there's no line terminator, it's not valid.