I'd like to do a search and replace on a bunch of filenames using regex values that are passed to the script from the command line argument which meand that the $1 or \1 will be in a string that I will be using in the regex.

Re: [ferulebezel] How Do I Use a regex back-reference in a Command Line Argument?
[In reply to]

Can't Post

I don't know what you are trying to do with $0.

But I worked on your problem for a day using $1 and parentheses around part of the regex. The problem is that when perl reads a string from the command line, perl doesn't interpolate variables contained in the string.

Therefore, you need to force perl to eval the replacement string in a context where $1 is visible--then perl will interpolate $1 into the replacement string. I couldn't figure out how to get eval() to do that, so I asked for help. It turns out, you can do everything inside s///, but the solution is pretty ugly. I would do it like this instead: