my $socket = IO::Socket::INET->new("$host:$port") or die "No connect: $!"; my $protocol = getprotobyname('tcp'); my $ok = 1; $socket->autoflush(1); while ( defined (my $msg_out = STDIN->getline) ) { last unless $ok; print $socket $msg_out; my $msg_in = <$socket>; print $msg_in; $bytes{'out'} += length($msg_out); $bytes{'in'} += length($msg_in); }