my $head = {data => 0, prev => undef, next => undef}; my $tail = $head; while (){ chomp; $tail = insert_after($tail, $_); }