You need to tell Perl that your string is multiple lines of text, using the "m" modifier:
(Note this assumes that foo and bar are going to be at the start and end of lines. It wasn't clear from your description whether "and a foo line to bar reject" should return nothing or "line to". Feel free to remove the ^ and $ to achieve the 2nd...)my $text = qq{foo this is one example bar this is a line I don't care about foo here's another keeper! bar foo yet another bar and a line to reject}; foreach ($text =~ /^foo(.*)bar$/gm) { manipulate($_); } sub manipulate { print $_, "\n"; }
Tony
In reply to Re: Delving the regexp underdark -- how to understand \G's behavior, or how to loop through a regular expression
by salvadors
in thread Delving the regexp underdark -- how to understand \G's behavior, or how to loop through a regular expression
by boo_radley
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |