in reply to Problem in sustitution of a string

Actually, that is not the message I see (nor quite what I would expect). I see:

Backslash found where operator expected at noname.pl line 5, near "s// +/\" syntax error at noname.pl line 5, near "s///\" Search pattern not terminated at noname.pl line 5.

The rule is: resolve the first error first. Perl is expecting to see either flag characters or a termination character such as ; - Perl doesn't expect to see a \, it makes no sense there.

What were you trying to achieve with the regex substitution? Replace the / with \? Instead try:

$a =~ s!/!\\!g;

Note the use if ! to delimit the regex so that / can be used unquoted, and also that \ needs to be quoted.

BTW: avoid the use of $a and $b except in the special context of sort.


DWIM is Perl's answer to Gödel