use strict; my $stop_flag = 0; my $timer; $timer = $mw->repeat(1000, sub{ #do something #check for stop_flag if( $stop_flag ){ $timer->cancel } });