foreach $host (sort @hosts) { $t = new Net::Telnet (Timeout => 10, Input_log => $file, Prompt => "/\>/"); print "\n\nConnecting to $host ...\n"; $t->open("$host"); $t->login("abc","abc123"); my @lines = $t->cmd('dir'); print "$host: Directory Contents:\n"; print "@lines \n"; $t->close; }