# Create a new main window object called $mw my $mw = new MainWindow(); # ... other GUI setup here # Call repeat to execute your subroutine every second (1000 milliseconds) my $loopStop = 0; # A pointer to this will be passed to the subroutine my $hour; # However this is calculated ... $mw->repeat(1000 => [ \&CheckTime, \$loopStop, $hour ]); MainLoop(); # The MainLoop goes last # And here's the subroutine sub CheckTime { my ($ploopStop, $hour) = @_; $exeTime=18; if ($$ploopStop == 0) { my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time); $ZWIDGETS{'Text1'} -> insert('end',"Waiting......\n"); if ($hour == $exeTime) { $ploopStop = 1; $ZWIDGETS{'Text1'}->insert('end', "Starting.....\n"); } } return $hour; }