http://www.perlmonks.org?node_id=787154


in reply to BEGIN { } block

Remember that use statements are implicitly emBEGINned - they're evaluated as soon as perl understands that they're there. So BEGIN blocks are actually evaluated not just when use is used, but before any other (non-BEGIN) code executes at all.

I've written a web application which uses BEGIN {} blocks to set up signal handlers for die()/warn() calls to do various site-specific stuff with them (like e-mailing the errors to the system admin so he knows there's problem afoot, and silencing warnings on the production site but making them fatal otherwise).