sub run_gui { my $choice = shift; ... ... sub { $mw->destroy } ... # instead of sub { exit } ... $$choice = $chosen; }