Use a non-greedy match (same as a greedy match, but with "?" after it).
use Data::Dumper; my $string = 'WhateverFooBlahBarMoreFooStuffBarMore'; my @words = ( $string =~ /Foo(.*?)Bar/g ); print Dumper \@words; __END__ $VAR1 = [ 'Blah', 'Stuff' ];
In reply to Re: Extracting substrings
by kyle
in thread Extracting substrings
by bontchev
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |