#!/usr/bin/env perl use IO::Socket; $remote_port=7071; $remote_host="localhost "; $socket = IO::Socket::INET->new(PeerAddr => $remote_host, PeerPort => $remote_port, Proto => "tcp", Type => SOCK_STREAM) or die "Couldn't connect to $remote_host:$remote_port : $@\n"; $socket->autoflush(1); # ... do something with the socket print $socket "ls:/tmp\n"; while (<$socket>) { print "$_\n"; } # and terminate the connection when we're done close($socket);