sub upto_list { my $from = shift; state $upto = shift; return undef if $from > $upto; return { head => $from, tail => sub { upto_list( $from + 1 ); }, }; } sub show { my $node = shift; my $i = shift // 10; while ($node->{head} && $i-- > 0) { say $node->{head}; $node = $node->{tail}->(); } } show( upto_list( 10, 15 ) );