You didn't escape the slash inside the char class. It might look like Perl should be smart enough to realize that the slash is inside a char class and isn't supposed to be a delimiter, since it complains about the pattern before it complains about syntax error after the pattern. (
m/\/?(.*)\/([^/ is the match op part and
]+\/?)/ is the following Perl code.) But that's just due to perl's optimization. perl compiles patterns at compile-time if it can. The pattern compilation is done before the rest of the program is parsed. Kind of like a BEGIN subroutine. This can be demostrated by making perl unable to compile the pattern at comile-time:
perl -e 'm/$a\/?(.*)\/([^/]+\/?)/'
Unmatched right square bracket at -e line 1, at end of line
syntax error at -e line 1, near "m/$a\/?(.*)\/([^/]"
Cheers,
-Anomo