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";