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


in reply to Restoring the magic to the _ filehandle in Perl 5.8.9

As you've stated, if you delay the execution of the code, there's no problem. I presume the reason you're using BEGIN is that the code inside will end up in a module. But you're not out of luck. Execution of INIT blocks are delayed until the main script has finished compiling.

If you change

BEGIN { *::_ = sub { # Shout to be understood return uc($_[0]); }; }
to
BEGIN { INIT { *::_ = sub { # Shout to be understood return uc($_[0]); }; } }

then the parser won't think the "_" in "-l _" is a function call since there's no function called "_" yet.

Caveat: Modules loaded after the script has been compiled...