#!/usr/bin/perl use strict; use warnings; use Win32; use Win32::API; use Win32::API::Callback; my $EnumWindows = Win32::API->new( "user32", "EnumWindows", "PN", "N" ); my $GetWindowText = Win32::API->new( "user32", "GetWindowText", "NPN", "N" ); my $title = qr/abc/; my $hwnd = 0; my $EnumWindowsProc = Win32::API::Callback->new( sub { my($acthwnd, $param) = @_; my $apptitle = ' ' x 256; my $len = $GetWindowText->Call($acthwnd, $apptitle, length($apptitle)-1); $apptitle = substr($apptitle, 0, $len); if ($apptitle =~ $title) { $hwnd = $acthwnd; return 0; } return 1; }, "NN", "N" ); $EnumWindows->Call( $EnumWindowsProc, 0 );