BEGIN blocks are called once when the script is compiled. END blocks are called when the Perl interpreter is unloaded.

This may cause surprising effects. Suppose, for instance, a script that runs in a forking web server and is loaded in the parent process. END blocks will be called once for each worker process and another time for the parent process while BEGIN blocks are called only by the parent process.

If the script reads from the DATA file handle, it reads the __DATA__ section provided by the script just as a normal script would do. Note, however, that the file handle is a memory handle. So, fileno DATA will return -1.