HI,
Try this,
Here it says that $x is not defined and therefore it creates a new local variable $x with 'my'.
Otherwise it uses the last value of x which is the default behaviour.
sub foo {
my $x if !defined $x;
return ++$x;
}
for (1..7){ print foo(); };