That code does the trick, although you may want to make it more generic if you're working on more complex strings. Also checkout using split() if possible.use Data::Dumper; my $string = "sp Hello there sp \n Hey hey sp How are you? sp"; my @result = $string =~ m< [ ]? # optional space sp # literal 'sp' [ ]? # optional space (.*?) # non-greedy capture [ ]? # optional space sp # literal 'sp' [ ]? # optional space >xg; print Dumper(\@result); __output__ $VAR1 = [ 'Hello there', 'How are you?' ];
_________
broquaint
In reply to Re: Regular expressions
by broquaint
in thread Capturing text between literal string delimiters (was: Regular expressions)
by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |