http://www.perlmonks.org?node_id=439735


in reply to Foreach Loops

You can have a counter:
my $i = 0; foreach (@myarray) { # stuff goes here $i++; }
A slight improvement over holli's in that you can access the entire i-1 previous elements.