use Net::Telnet; my $telnet3; $telnet3 = new Net::Telnet(timeout => 10, Errmode => 'die'); $telnet3->open('ip_address'); $telnet3->login('username', 'password'); @lines = $telnet3->cmd("who"); open(FILE, ">file.txt"); print FILE ("@lines\n"); print("logged in to the device.\n");