$head ={ data=>2 next=>undef; ## or the next node to which it is linked to } #### my @elements; my $curr=$head; ## I am trying to make my curr pointer start from the head while (1){ last unless ($curr->{next} == $head); # here I am trying to check that the next element is not head. And if is then break out of the loop print "data : $curr->{data} \n"; push(@elements,$curr->{data}); $curr = $curr->{next}; }