#!/usr/bin/perl use warnings; use strict; use IO::Socket::INET; $/ = "\r\n"; my $socket = IO::Socket::INET->new( PeerAddr => 'localhost', PeerPort => 3009, Proto => 'tcp', ) or die "Couldn't open socket: $!"; print "Registering yarr.\n"; print $socket "REG yarr\n"; while (<$socket>) { chomp; print "Received $_\n"; next unless (/^yarr/); my $reply = "Yarr!"; # Put the reply after the second field, removing the first field. s/^([^\t]*\t)([^\t]*)/$2 $reply/ || next; print "Saying", $_, "\n"; print $socket $_, "\n"; }