#!/usr/bin/perl use warnings; use strict; use Tk; sub periodically { warn "Testing the file existence...\n"; } my $mw = MainWindow->new(-title => 'Test'); my $repeat = $mw->repeat(1000, \&periodically); $mw->bind('', sub { $mw->afterCancel($repeat) }); MainLoop();