in reply to Re^4: eval sub
in thread eval sub

...I am not sure why I wasn't getting the "Too many arguments..." error in my direct call to mySub("Hello world")

The reason for this is that the error is thrown at compile time. In the case of the direct call, the subroutine definition (and its prototype) isn't known yet, as it gets eval-ed later at runtime...

Put that code in a BEGIN {...} block, i.e.

BEGIN { my $code = << 'EOC'; sub mySub() { print "args: @_\n"; } EOC eval $code; } ...

and you'll see the difference. Due to the compilation error, the script now doesn't run at all:

$ ./716452.pl Too many arguments for main::mySub at ./716452.pl line 19, near ""hell +o world")" Execution of ./716452.pl aborted due to compilation errors.