use strict; use IO::Socket; use IO::Socket::INET; use threads; my $sock = IO::Socket::INET->new(PeerAddr => $server, PeerPort => 6667, Proto => 'tcp') or die "Can't connect\n"; my $sock2 = IO::Socket::INET->new(PeerAddr => $server2, PeerPort => 9999, Proto => 'tcp') or die "Can't connect\n"; my $thread1 = Thread->create(&gateway2irc); $thread1->join(); my $thread2 = Thread->create(&chat2gateway); $thread2->join(); sub gateway2irc { while (my $input = <$sock>) { chomp($input); if ($input =~ /^PING(.*)$/i) { print $sock "PONG $1\r\n"; } } } sub chat2gateway { while (my $input2 = <$sock2>) { if ($input2 =~ "ping") { print sock "PRIVMSG $channel : ping\n"; } } }