sub Counter { my $i = 0; return sub { print $i++."\n"; } } my $counter = Counter; $counter->(); $counter->();