while() { chomp; if ($_ ne "") { print TERMINAL "$_\n"; # print the contents of the screen if ($_ =~ /Username:/) { print STDOUT "$username\r"; } elsif ($_ =~ /Password:/) { print STDOUT "$password\r"; } }