sub foo { my ($reset) = @_; my $x if $reset; # Will reset at end of scope if $reset is true. return ++$x; } print foo(0), "\n"; # 1 print foo(0), "\n"; # 2 print foo(1), "\n"; # 3 print foo(0), "\n"; # 1 print foo(0), "\n"; # 2