use strict; use warnings; use Win32::GuiTest qw(:ALL); foreach my $like ( 'Excel', 'Book1 - Excel', 'Book1.xslx - Excel', 'Book1') { my @window = FindWindowLike(undef, $like); unless (@window) { warn "Couldn't find '$like'\n"; next; } print $like, @window; foreach (@window) { SetForegroundWindow( $_ ); SendKeys(join '{TAB}', "Hello World", $like, $_, GetWindowText($_), "{ENTER}"); #MenuSelect("&File|&Save"); #MenuSelect("File|Save"); SendKeys('%FS'); } } __END__ __OUTPUT__ Excel 1903500 6817874 1580572 Couldn't find 'Book1 - Excel' Couldn't find 'Book1.xslx - Excel' Book1 1903500 4919696