my $i = 0; foreach (@myarray) { # stuff goes here $i++; }