$line =~ s/\Q$var2\E/$var1/; [download]
In reply to Re: using variables in regular expr replace by Joost in thread using variables in regular expr replace by b888