sub generator { ... my $frobnosticator = 0; my $coderef1 = sub{ ...; $frobnosticator ^= 1; ... }; my $frobnosticator = 0; my $coderef1 = sub{ ...; $frobnosticator ^= 1; ... }; return $coderef1, $coderef2; }