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}; }