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

Thanks almut,

You are right, I forgot that on the first time $_ contains the original value so in the next iterations there is no match at all, I created the local var in the loop so I never change my template:

for ($counter=0; $counter<$total; $counter++) { foreach (@template) { my $line = $_; $line =~ s/$replacement/${prefix}-${counter}/; print $line; } }
JavaFan, I don't think that was what I needed but thanks!