use Tk; my $file; my $top = new MainWindow; my $ent = $top->Entry(-textvariable=>\$file)->pack(); my $but = $top->Button(-text=>"ShowFile",-command=>\&sub_file)->pack(); MainLoop(); sub sub_file { print $file; # or whatever }