use IO::Socket; use strict; my $location = '123.456.123.456:8000'; my ($sock, $out); $sock = new IO::Socket::INET ( PeerAddr => $location, Proto => 'tcp', ); die "Could not create socket: $!\n" unless $sock; while (1) { sendInput($sock, getInput('Enter a command')); $out = getOutput($sock); last if !$out; print $out; } close($sock); ### Query user for input sub getInput { my ($query, $null) = @_; my $in; do { print "$query : "; chomp($in = ); } while !$null && !$in; return $in; } ### Send to socket sub sendInput { my ($handle, $inp) = @_; $inp .= "\n" if $inp !~ /\n$/; print $handle $inp; print $handle "\n"; } ### Get result sub getOutput { my $handle = $_[0]; my $output; while (<$handle>) { last if !m/\S/; $output .= $_; } return $output; }