The second is standalone because it's general purpose and I didn't want to rewrite it every place I want to use it.
Points for reuse, but I think your approach has lots of unintended consequences that will require the parent and child to be more complex as a result. You can have the child exit with various codes that your parent can interpret and act accordingly, and that's not really that complex, but will the child be providing other user-supplied information back to the parent? Will the child be around for long time? For example, under your current strategy, your parent will not be able to receive events until the child is done (exits), unless you're using something like fileevent.
My suggestion would be to create a module out of your reused second window, and treat the second window as a dialog box. for your parent. Your code will be much simpler as a result. Update: (see my followup for examples)
is there a way to catch that 'x' signal?
Yes. What you're looking for is something like this:
use Tk;
my $mw = MainWindow->new;
$mw->protocol(WM_DELETE_WINDOW => sub {
print "Exiting appliction!\n";
exit;
});
MainLoop;
Rob