$mw->Button( -text => "Submit", #-command => sub {exit} # no good, will exit whole program -command => sub{ $mw->destroy } # good )->pack(); #### .... Tk code omitted MainLoop; # after running $mw->destroy, the following lines will get processed here, right after the MainLoop line # if you have an external program to feed $text to, try one of these system( "path_to_program $text"); #or exec ( "path_to_program $text"); # if you want to run your program and get ouput use IPC::Open3; my $pid = open3(\*WRITE, \*READ, \*ERROR,"your_command"); if( ! $pid ){ die "$!\n";} #send $text to your_command's STDIN print WRITE "$text\n"; #get the answer from your_command chomp(my $answer = ); print "response = $answer\n"; #get the error from your_command chomp(my $error = ); print "error = $error\n";