use Win32::GuiTest qw/ FindWindowLike SetForegroundWindow GetDesktopWindow IsWindowVisible /; my @handles = grep {IsWindowVisible($_) } FindWindowLike(GetDesktopWindow(), qr/^Microsoft Excel/, undef, undef); die "Too many windows\n" if (@handles > 1); die "Not enough windows\n" if (@handles < 1); my $excel = shift @handles; SetForegroundWindow($excel);