Other monks have given good solutions, but you might also be want to know what your mistakes are.
First, you can't use the $1 and $2 special variables in a formula before they have been set by a regular expression. In other word, they are undefined at the point where you're using them in the conversion formula.
Second, I am not sure why you enclose them within curly braces then is no need to do that. If you want to isolate them from neighboring characters (not needed here), then the proper syntax is ${1}, not {$1}.
Finally, it seems from the error messages you get that your input file is not properly opened. When you open a file, you should always check if the statement worked:
Update: fixed a typo on the filename on the preceding line. Thanks, soonix.open IN,'<',"part2.txt" or die "could not open file part2.txt $!";
In reply to Re: substitution with regex
by Laurent_R
in thread substitution with regex
by drose2211
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |