my %ssh; for my $host (@hosts) { $ssh{$host} = Net::OpenSSH->new($host, async => 1, ...); } for my $host (@hosts) { my $ssh = $ssh{$host}; my ($pty, $pid) = $ssh->open2pty; # whith out command launchs a shell my $expect = Expect->init($pty); $expect->... }