use IO::Socket; #To flush the buffer print statements $| = 1; my $sock = new IO::Socket::INET( PeerAddr => 'localhost', PeerPort => 7890, Proto => 'tcp'); if ($sock) { print "A tcp socket on localhost connected to 7890\n"; } else { die "Error: $!"; } $nonblocking = 1; ioctl($sock, 0x8004667e, \$nonblocking); $buf = "1234567890"; syswrite($sock, $buf, 10); sysread($sock, $buf, 10); $sock->flush; print "Bytes 10 = $buf\n"; syswrite($sock, "1", 1); print "\n"; $sock->flush; sysread($sock, $buf, 2); print "Bytes 2 = $buf\n";