use IO::Socket; use IO::Select; use IO::Handle; $A = new IO::SOCKET::INET (LocalHost => 'localhost', LocalPort => 1234, Type => SOCK_STREAM, Proto => "tcp", Reuse => 1, Listen => 5) or die "A Server socket couldn't be created: $@\n"; $B_listen = new IO::SOCKET::INET (LocalHost => 'localhost', LocalPort => 5555, Type => SOCK_STREAM, Proto => "tcp", Reuse => 1, Listen => 5) or die "B Server socket couldn't be created: $@\n"; my $B_clients = new IO::Select(); my $pid = fork(); if ($pid) { #PARENT while($A_sock = $A->accept()) { #Will only have 1 connection while(defined($buf=<$A_sock>)){ my @client_set = $B_clients->can_write; foreach my $client (@client_set) { print $client $buf; } } } } else { #CHILD while($B_sock = $B_listen->accept()) { $B_clients->add($B_sock); } }