The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.
use Win32::GuiTest qw(FindWindowLike GetWindowText SetForegroundWindow);

$Win32::GuiTest::debug = 0;

my @windows = FindWindowLike(0, "Excel", "", 0, 1);

for (@windows) {
    print "$_>\t'", GetWindowText($_), "'\n";
}

print "------------\n";

@windows = FindWindowLike(0, "^Microsoft Excel", "^XLMAIN\$");
for (@windows) {
    print "$_>\t'", GetWindowText($_), "'\n";
    SetForegroundWindow($_);
}

print "------------\n";

die "You should start Excel before running this example.\n"
    unless @windows;

my @children = FindWindowLike($windows[0]);
for (@children) {
    print "$_>\t'", GetWindowText($_), "'\n";
}