The BEGIN block is evaluated as soon as it is defined. Therefore, it can include other functions using do() or require statements. Since the blocks are evaluated immediately after definition, multiple BEGIN blocks will execute in the order that they appear in the script.
For Example (export.pl):
The Perl code is (export.pl):
BEGIN { print("main\n"); } package Foo; BEGIN { print("Foo\n"); }
This program displays:
main Foo