#! perl -slw use strict; use IO::Socket; my $socket = IO::Socket::INET->new( PeerAddr => '127.0.0.1', PeerPort => 6969, Proto => "tcp", Type => SOCK_STREAM ) or die "Couldn't connect to 127.0.0.1:6969 : $@"; # ... do something with the socket print $socket "Why don't you call me anymore?"; chomp( my $answer = <$socket> ); print "Got: $answer"; # and terminate the connection when we're done close($socket);