use strict; use warnings; use Tk; my $mw = Tk::MainWindow->new(); $mw->Button( -text => "Exit", -command => sub { $mw->destroy(); } )->pack(); # or $mw->Button( -text => "Exit", -command => \&pressExitButton )->pack(); MainLoop(); sub pressExitButton { $mw->destroy(); }