use Socket;

sub open_TCP
{
  # get parameters
  my ($FS, $dest, $port) = @_;

  my $proto = getprotobyname('tcp');
  socket($FS, PF_INET, SOCK_STREAM, $proto);
  my $sin = sockaddr_in($port,inet_aton($dest));
  connect($FS,$sin) || return undef;

  my $old_fh = select($FS);
  $| = 1;                       # don't buffer output
  select($old_fh);
  1;
}

if (open_TCP(S,$HOST,$PORT)==undef) {
  die "Can't open host";
}
print S "GET " . $URL . "\n";
while (<S>) {
# do whatever you like in here
}
close(S);