in reply to Parens mess up regex substitute
While all of the above answers are correct, I think they may be slightly missing the point of your question. What I understand you're asking is: "Why do the parens in $str do not screw up
(my $name = $str) =~ s{.*/}{}; # basename
but do screw up
(my $path = $str) =~ s{$name}{};
?"
And the answer to that is: they don't. It's not the parens in $str that are the problem in the second substitution, it's the parens in $name
In Section
Seekers of Perl Wisdom