use Win32::GuiTest qw(FindWindowLike GetWindowText SetForegroundWindow SendKeys); system('"start %windir%\system32\mstsc.exe"'); sleep(1); $Win32::GuiTest::debug = 0; # Set to "1" to enable verbose mode my @windows = FindWindowLike(0, "Remote Desktop Connection"); for (@windows) { SetForegroundWindow($_); SendKeys("Server"); SendKeys("{ENTER}"); sleep(10); my @windows1 = FindWindowLike(0, "Windows Security"); print scaler @windows1; for (@windows1) { SetForegroundWindow($_); SendKeys("password01"); SendKeys("{ENTER}"); } }