in reply to How do I stop this from being a never ending loop

@link in scalar context will give the number of elements in the array, not the index of the last element so you will try to access an element off the end of the array (whether this is the problem I'm not sure). You need to use $#link instead. So you could do

for( $i = 0; $i <= $#link; $i++ ) { ...

A more Perlish way would be

for my $i ( 0 .. $#link ) { ...

I'm not sure why you de-reference $link_ref and assign it to @link. You could do

for my $i ( 0 .. $#{ $link_ref } ) { my $links = $link_ref->[ $i ]->[ 0 ]; }

I hope this is of interest.

Cheers,

JohnGG