in reply to looping through array references

I echo GrandFather's reply.

I'd also like to emphasize that Super Search is your friend. Searching for 'loop array index' finds a couple of recent threads that are quite relevant:

Those threads mention functions from two modules (in case you'd rather use one than roll your own method): each from Array::Each::Override and natatime from List::MoreUtils. After looking through the docs for the latter I think each_array is more appropriate here.
use warnings; use strict; use List::MoreUtils qw( each_array ); my @array = ( 'a' .. 'g' ); my $a_obj = each_array( @array ); while( my $var = $a_obj->() ) { my $i = $a_obj->( 'index' ); print "got $var at $i\n"; }
got a at 0 got b at 1 got c at 2 got d at 3 got e at 4 got f at 5 got g at 6