In the last example, the expression is parsed as a(*2) , which calls a with the argument glob *2 , which is the short name of the package variable *main::2
If you want a parsed as a function that takes no arguments, you need to declare it as follows:
sub a () {2 + 2}
Then perl will parse the statement as you expected. In fact, if you write it like this, perl will determine that it is a constant function, and will be inline 4 anywhere where a would be called.
source share