I would like to substitute a substring that contains an @ character with Perl as in the following sed command:
substitution='newusername@anotherwebsite.com'
sed 's/oldusername@website.com/'"${substitution}"'/g' <<< "The current e-mail address is oldusername@website.com"
At present wherever I use Perl instead of sed or awk I first replace \ with \\, / with \/, $ with \$ and @ with \@; e.g.
substitution='newusername@anotherwebsite.com'
substitution="${substitution//\\/\\\\}"
substitution="${substitution//\//\\/}"
substitution="${substitution//$/\\$}"
substitution="${substitution//@/\\@}"
perl -pe 's/oldusername\@website.com/'"${substitution}"'/g' <<< "The current e-mail address is oldusername@website.com"
I have read about using single quotation marks (as below based on sed/ perl with special characters (@)) but I was wondering if there is any other way to do this with forward slashes?
substitution='newusername@anotherwebsite.com'
perl -pe "s'oldusername@website.com'"${substitution}"'g" <<< "The current e-mail address is oldusername@website.com"
Also, are there special characters in Perl aside from $, @ and % (and why is there no need to escape %)?