The pipe | char is a regex meta character and therefore needs to be escaped if you want to use it as a literal.
Substituing the following for the equivalent line of your script should solve the problem
s/\Q$rem\E/$rep/go;
In reply to Re: replacing pipe "|"
by BrowserUk
in thread replacing pipe "|"
by nadadogg
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |