use Win32::GuiTest qw(FindWindowLike SetForegroundWindow SendKeys); system("start p.bat"); # start ensures that the program opens in a new window sleep(1); # give p.bat a chance to load my @win = FindWindowLike(0, "^p.bat"); # find p.bat's window (maybe more than one) SetForegroundWindow($win[0]); # bring the first p.bat window to the foreground SendKeys("y"); # send a keypress to the active window in this case a "y" __DATA__ For this example, p.bat contains one line: pause