You need to quote your string with \Q\E because it contains | which in a regex means or. What you want is:
$line =~ s/\Q$delimiter\E/\,/g;
Note that your original code acted as a "match anything" so it interspersed a comma between each character in the target string.
In reply to Re: Using variable in substitute regex producing odd results
by GrandFather
in thread Using variable in substitute regex producing odd results
by punch_card_don
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |