http://qs1969.pair.com?node_id=11141080


in reply to Using sprintf in regular expreession.

s/PATTERN/REPLACEMENT/msixpodualngcer:
>> e Evaluate the right side as an expression.

The whole right side of the regex is evaluated.
You can't make some parts of the REPLACEMENT evaluated and some not. So you should wrap "$3-" and "-$2" in doublequotes and join all parts by concatenation, e.g.: $date =~ s/(\d+)-(\d+)-(\d+)/ "$3-" . sprintf("%02d",$1) . "-$2" /ge;

Upd. You need double quotes to interpolate $3 and $2 (single quotes won't).