while($index < $#array+1){ $last=pop(@array); [download]
You modify your @array while iterating over it. Don't.
In reply to Re: $#array issue by shmem in thread $#array issue by biohisham