Default variable

The most used special variable is $_, which is a default scalar variable. To understand it better let's look at the examples.

You're familiar with say function. It prints whatever you pass as arguments. But what happens when you don't pass any arguments? It takes data from the default $_ variable.

$_ = 'Hello';
say;

Of course you don't usually need this functionality, but it can very useful when using loops, for example:

say for (1 .. 10);

By default for loop sets a $_ variable and say prints it.

Many embedded Perl functions use default variable when no arguments are passed.