#!/usr/bin/perl use Tk; use strict; use warnings; my $count = 0; my $count_on = 0; my $window = MainWindow->new; $window->title("My Example"); $window->Label(-textvariable => \$count )->pack; $window->Button( -text => "Start", -command => sub {$count_on = 1}, )->pack; $window->Button( -text => "Stop", -command => sub {$count_on = 0}, )->pack; my $timer = Tk::After->new($window, 1000, 'repeat', sub { $count++ if $count_on }); MainLoop;