This little bit of code might help. In the bigger picture, you probably shouldn't be calling die or exit, just to catch bad user input, use validation rountines on Entrys, etc.
#!/usr/bin/perl
use warnings;
use strict;
use Tk;
require Tk::ErrorDialog;
my $mw = new MainWindow;
$mw->title("Close test");
$mw->geometry("400x250");
#prevents mw from closing
$mw->protocol('WM_DELETE_WINDOW' => \&save_it );
$mw->after(2000, sub{ die } );
MainLoop;
sub save_it {
print "do stuff here before the exit\n";
$mw->messageBox(-message=>"you tried to exit!");
}