for my $index (0..$#parts) { my $i = $index; # unique per loop iteration ... rest of your loop here ... }