#! perl -slw use strict; use threads; use Thread::Queue; use IO::Socket; my $Q = new Thread::Queue; my @threads = map async { while( 1 ) { my $s = IO::Socket::INET->new( $_ ) or die $!; while( my $input = <$s> ) { $Q->enqueue( $input ); } sleep 5; } }, 'localhost:12345', 'localhost:6789'; while( my $input = $Q->dequeue ) { chomp $input; if( $input =~ m[Z:] ) { ## Deal with telemetry print "Got telemetry: '$input'"; } else { ## Deal with waypoint; print "Got waypoint: '$input'"; } }