in reply to Re^3: when is a perl module executed?
in thread when is a perl module executed?

You asked if placing code in a package outside subroutines is "right".

I'm afraid that what is "right" is not that clear cut, it is often a matter of opinion. If you get the result you need then there is a case for saying it is "right". Whether the code is clear, easy to maintain, and efficient is another matter, and often not easy to quantify.

A BEGIN block is specifically provided for code to be executed once at compile time. Usually this is the best place to put it since it is easy to find. There are some cases where you do need code outside the BEGIN block, but not many. The bulk of a package is "usually" invoked at runtime using subroutines, not "always".