use IO::Socket; $sock = new IO::Socket::INET( PeerAddr => 'localhost', # an IP here and the script fails to connect PeerPort => 1200, Proto => 'tcp' ); die "Socket could not be created: $!\n" unless $sock; $msg = ; while ( $msg !~ m/^\n$/ ) { $inp = $msg; undef( $msg ); print $sock "MSG: $inp"; $sock->flush(); $msg = ; } close( $sock );