in reply to Why a regexp won't increment the value of a variable
my $counter = 0; foreach (@template) { $counter++ if s/$replacement/${prefix}-${counter}/; print; } [download]