use threads; #lets us make threads use threads::shared; #lets us share variables between threads my $job_done : shared = 0; #allow the main thread to notify the child thread it is done. sub watcher { my $error = 0; until ($job_done) { if (error windows appeared) { $error = 1; } sleep 1; #use Time::HiRes qw(sleep) or select(undef, undef, undef, 0.5) if you need less than 1 second testing } return $error; } my $watcher = threads->create \&watcher; #start the watcher thread system(call the program); #this will tie up the main thread until it finishes $job_done = 1; #this should let the thread exit on the next loop my $error = $watcher->join; #clean up the thread and get it's return.