in reply to Run subroutine occasionally

consider: $MW->repeat($MILLISECOND_DELAY, \&someSub);
runs someSub repeatedly.

Of course, sub someSub{} should run "quickly" or the GUI will "freeze".

Update: I re-read the question and perhaps I made an incorrect about this being a Tk GUI? If so, the OP needs to clarify.

Update with Code for a GUI:

use strict; use warnings; use Tk; # quick hack # reports the last function button pressed # every 3 seconds # Doesn't start reporting until first button is pressed. my @buttons = (["function1", \&func1], ["functoin2", \&func2], ["function3", \&func3],); my $last_function_executed =0; sub func1{ print "this is function 1\n"; $last_function_executed = 1; } sub func2{ print "this is function 2\n"; $last_function_executed = 2; } sub func3{ print "this is function 3\n"; $last_function_executed = 3; } sub report_last_func{ return unless $last_function_executed; # no button pressed yet! print "most recent operation was: $last_function_executed\n"; } my $MW = MainWindow->new(); foreach my $button_ref (@buttons) # create buttons { my ($text,$subref) = @$button_ref; $MW->Button(-text=> $text, -command => $subref)-> pack; } $MW->repeat(3*1000, \&report_last_func); MainLoop;