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.

In reply to Re: about read HTTP header. by pemungkah
in thread about read HTTP header. by iic

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.