use Iterator; my $i = 0; sub get_a { return new Iterator(sub { print "a called\n"; return $i++ }); } sub get_b { my $a = get_a; return new Iterator(sub { print "b called\n"; return $a->value }); } print "Now I will get_b ($i):\n"; $b = get_b; print "Got b ($i)\n"; print "First value is ($i):\n"; print "b: ", $b->value, " ($i)\n";