#!/usr/bin/perl use 5.010; use strict; use warnings; use IO::Socket::INET6; while () { print "> "; my $command = ; my $addr = $command =~ s/^4// ? '127.0.0.1' : '::1'; my $socket = IO::Socket::INET6->new( PeerAddr => $addr, PeerPort => 20_000, Proto => 'tcp', ) or die "error creating socket: $@\n"; print $socket $command; print scalar <$socket>; close $socket; last if $command =~ /^quit|exit|bye/; }