use strict; use warnings; use feature 'say'; my $it = MakeCounter(); say $it->() for 1 .. 3; sub MakeCounter { my $count = 0; return sub {return ++$count;}; }