#!/usr/bin/perl use warnings; use strict; use Tk; my $mw = tkinit; my $tl = $mw->Toplevel(-title=>"Stupid Program"); my $text = $tl->Text()->pack(); my $flag = 0; my $cancel_btn= $tl->Button(-text=>"Cancel", -command=> sub { $flag = 1; $tl->withdraw })->pack(-side =>'left', -expand=>1, -anchor => 'center'); my $do_btn= $tl->Button(-text=>"Start", -command=> sub { while (){ # process data # output to a text widget if($flag){last} $text->insert('end',"$_\n"); $text->update; $mw->after(1000); } })->pack(-side =>'left', -expand=>1, -anchor => 'center'); MainLoop; __DATA__ 1 2 3 4 5 6 7 8 9 10