http://www.perlmonks.org?node_id=103568

kingman has asked for the wisdom of the Perl Monks concerning the following question:

Hi, I just read [id://20361|How would I replace the string 'Red1' with $Red1?]
But I still can't figure this out. Here's the code:
$n = 0; $html_file_slurped_to_a_scalar =~ s/<img .*?>/«TOKEN_$n++»/gis;
This turns all img links into «TOKEN_0++»; $n interpolotes but doesn't increment.
If I add the /e modifier, the complier chokes when it tries to evaulate «
Unrecognized character \xAB at /path/foo line 25.
Maybe I'm trying to do too much but I'd like to avoid the following loop if I can:

evaluate $html_file_slurped_to_a_scalar
change the first image tag to «TOKEN_$n»
increment $n

Any suggestions?