sub transform { my ($ref) = @_; $$ref = 'tripped'; } $text = 'The brown cow jumped over the moon'; if ( $text =~ m/cow\s+(jumped)\s+over/ ) { my $ref = \substr($text, $-[1], $+[1] - $-[1]); transform($ref); } print("$text\n"); # The brown cow tripped over the moon
Update: Expanded the example to be runnable.
In reply to Re^2: Manipulating the Capture(s) of Regular Expressions
by ikegami
in thread Manipulating the Capture(s) of Regular Expressions
by monarch
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |