static (state) variables

examples/feature/static.pl
#!/usr/bin/perl 
use strict;
use warnings;

{
   my $counter = 0;
   sub next_counter {
      $counter++; 
      return $counter;
   }
}

print next_counter(), "\n";
print next_counter(), "\n";

examples/feature/state.pl
#!/usr/bin/perl 
use strict;
use warnings;

use 5.010;

sub next_counter {
    state $counter = 0;
    $counter++;
    return $counter;
}


say next_counter();
say next_counter();