So... assuming this is actually perl, and not something else using PCREs, then this actually seems to work:
my $string = "a_sample_string";
$string =~ m/(?{ tr|_| | })(.*)/;
print $1;
That said, this is terribly fragile and dangerous. I wouldn't actually do that. You are essentially reaching out from the inside regex and altering the match variable before trying to match. It does manage to meet your criterion, though.
Update: Remember that this is actually a destructive match, though... you aren't just returning $1, but also altering the match input, wherever that comes from. This will fail if the match input is immutable.
|