my $first; my $prev_node; for (1..5) { my $node = { value => $_, prev => $prev_node }; $first //= $node; $prev_node->{next} = $node; $prev_node = $node; } my $node = $first; while ($node) { say $node->{value}; $node = $node->{next}; }