Say you wanted to create a linked list of the first five squares...
$list = [$list, $_*$_] for reverse(1 .. 5);
Of course that would mean making the linked list the king of the data. Sometimes you want to concentrate on the data, and worry about the linked list structure less. In that case, you can simply add a "next" field to each element, and store a reference to the next element.
Here is another way to create the linked list if you wanted to maintain a tail pointer.
$list = undef;
$tail = \$list;
for(1 .. 5) {
$elem = [undef, $_ * $_];
$$tail = $elem;
$tail = \$elem->[0];
}
In this case, we're setting $tail to be a reference to the "thing that needs to change when a new element is appended to the list". The thing that needs to change is of course the "next" reference of the last element. So we always keep $tail pointing to that. The first $$tail is following that reference and storing a reference to the newly created element there. The next $tail is updating the tail to point to the "next" of the element we just added.