I have written the following code to create a simple linked list, and walk through it, printing each element:

use strict;

my $list = undef;

for (reverse 0..10){
        $list = [$list, $_ * $_];
}


sub walk_list {
        my $head = shift;
        my $steps = shift;
        my $action = shift;

        while ( $steps && $head->[0] ){
                $action->($head);
                $head = $head->[0];
                $steps--;
        }
}

my $print_list = sub {my $node = pop; print $node->[1], "\n";};

walk_list($list, 10, $print_list);

Two questions:

1) Why does it only print up to 81 instead of the expected 100?
2) Why does the anonymous sub that I currently have in $print_list work fine, however this: