use constants TIMEOUT => 50; use constants wbemErrTimedOut => 0x80043001; while (1) { $o1 = $h1->NextEvent(TIMEOUT); ProcessEvent1($h1, $o1) if ($o1 != wbemErrTimedOut); $o2 = $h2->NextEvent(TIMEOUT); ProcessEvent2($h2, $o2) if ($o2 != wbemErrTimedOut); }