my $w; $w->{main} = MainWindow->new; $w->{other_widgets} = $w->{main}->Label->.... # and then later... &subroutine($w); sub subroutine { my $w = shift; # Do stuff with $w here now like normal $w->{main}->configure( -title => "new title" ); } #### 1 if $a; # for example #### sub unused { warn "sub unused was used!!!\n"; return; 1 if $a; 1 if $b; } #### #! /usr/bin/perl -w use strict; use Tk; use Tk::Toplevel; ################ # Main Routine # ################ my $w; $w->{main} = MainWindow->new(-title => 'Tk Hash'); $w->{main}->Button(-text => "Click me to open a new toplevel", -command => [ \&new_tl, $w ])->pack; $w->{main}->Button(-text => "Click me to test for other button", -command => [ \&test_tl, $w ])->pack; MainLoop; exit; ############### # Subroutines # ############### sub new_tl { my $w = shift; if ( not Tk::Exists $w->{toplevel} ) { $w->{toplevel} = $w->{main}->Toplevel( -takefocus => 1, -title => 'Top Level' ); $w->{testbutton} = $w->{toplevel}->Button(-text => 'Null button'); } else { $w->{toplevel}->deiconify(); $w->{toplevel}->raise(); $w->{toplevel}->focusForce(); } } sub test_tl { my $w = shift; if ( Tk::Exists $w->{testbutton} ) { print "testbutton exists\n"; } else { print "testbutton does not exist\n"; } }