in reply to Why a regexp won't increment the value of a variable

Perhaps you want something like:
my $counter = 0; foreach (@template) { $counter++ if s/$replacement/${prefix}-${counter}/; print; }