use IO::Socket; use strict; use warnings; my $PORT = shift or die "Please specify First port number\n"; #my $file = shift or die "Please specify input file\n"; my $socket = IO::Socket::INET->new('LocalPort' => $PORT, 'Proto' => 'tcp', 'Listen' => 2) or die "Third: Can't create socket to Second($!)\n"; my $match = "brenna"; print "Third listening\n"; while (my $second = $socket->accept) { #setup acknowledgement message to Second my $host = gethostbyaddr($second->peeraddr, AF_INET); my $port = $second->peerport; while (<$second>) { my $name = $_; chomp($name); print "[$host $port] $name\n"; #print $socket "$.: $name\n"; if($name eq $match) { print "Third sending \"$name\" to Second\n"; print $socket "$name\n"; #close $second or die "Can't close ($!)\n"; } } } die "Third: Can't accept receive socket from Second($!)\n";