in reply to Re^2: Working in parallel
in thread Working in parallel

Sure, I'll use IO::Select for simplicity's sake, though I normally would use AnyEvent::Handle.

use strict; use warnings; use Net::Telnet; use IO::Socket; use IO::Select; use Data::Dumper; my @hosts = ('localhost')x2; my %results; $t1->open( Host => $hosts[0] ); $t2->open( Host => $hosts[1] ); my $s = IO::Select->new( $t1, $t2 ); $t1->send('start first comand'); $t2->send('start second command'); while ( $t1 && $t2 ) { while ( my @ready = $s->can_read() ) { foreach my $fh (@ready) { if ( $t1 && $t1 == $fh ) { my $line = $t1->getline; push @{ $results{t1} }, $line; $s->remove($t1); $t1->close; undef $t1; } elsif ( $t2 && $t2 == $fh ) { my $line = $t2->getline; push @{ $results{t2} }, $line; $s->remove($t2); $t2->close; undef $t2; } } } } print Dumper( \%results )

This is just an example, it only gets the first line returned from the connection and then closes the connection (not what you would really do). Before you start the select loop you could do whatever Net::Telnet preparation you need (logging in, sending commands, etc).