use strict; use warnings; use Tk; my $mw = MainWindow->new(); $mw->Label( -text => "Wait", -font => [-family => 'times', -size => 20], )->pack(-expand => '1', -fill => 'both'); $mw->MainLoop; doSomething($mw);#this is doing nothing here, it should be automatically called after creation and display of mainwindow sub doSomething{ my $mw = shift; print "Hello!\n"; $mw->destroy; }