use strict; use warnings; my $str = "hello\nworld"; my ($first, $last); $str =~ m/ (?{ $first = substr($str, 0, 1); $last = substr($str, -1) } +) /x; print "first: '$first'; last: '$last'\n";
However note the caveats of (?{ ... }) groups as documented in perlre.
In reply to Re: regex for string
by moritz
in thread regex for string
by saranperl
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |