in reply to Re: Why can't $` $& $' be enabled on a per-regex basis?
in thread Why can't $` $& $' be enabled on a per-regex basis?

Be sure to note that it doesn't work for substitutions:

sub prematch (;$) { substr((@_ ? $_[0] : $_), 0, $-[0]) } sub match (;$) { substr((@_ ? $_[0] : $_), $-[0], $+[0] - $-[0]) } sub postmatch (;$) { substr((@_ ? $_[0] : $_), $+[0]) } my $foo = 'Hello, world!'; $foo =~ s/l+/r/; print "prematch(",prematch($foo),")\n"; print "match(",match($foo),")\n"; print "postmatch(",postmatch($foo),")\n"; print "`(",$`,")\n"; print "&(",$&,")\n"; print "'(",$',")\n";
produces
prematch(He) match(ro) postmatch(, world!) `(He) &(ll) '(o, world!)

        - tye (but my friends call me "Tye")