\1 is a regular expression atom that matches the capture of the first capture. It makes no sense to use it in a replacement expression. You want $1 .
$ perl -we'$_="abc"; s/(a)/\1/' \1 better written as $1 at -e line 1.
In a string literal (including the replacement wildcard expression), you can delimit $var with curlies: ${var} . This means that you want the following:
s/([^0-9])([xy])/${1}1$2/g
Below is a more efficient one (although it gives a different answer for xxx ):
s/[^0-9]\K(?=[xy])/1/g
source share