# create socket $sock with IO::Socket or similar my @headers; while (<$sock>) { last unless /\S/; # end on a blank 'line' ("\n\n"), like in HTTP chomp; push @headers, $_; } while (defined($_ = getc($sock))) { my $dec = ord($_); # process eithier $_, the ascii equivilent or $dec, the decimal value }