#!/usr/bin/perl use strict; use warnings 'all'; use Tk; use threads; my $thr = threads->new(sub { (print("An!\n"), sleep 1) while 1 }); my $mw  = tkinit; $mw->Button(-text => "Start", -command => sub { threads->yield; $thr->join })->pack; $mw->Button(-text => "Stop!", -command => sub { $thr->detach })->pack; MainLoop;