It works if you add an end marker for the right part:
Edit: \s* rather than \s+ to allow empty section at EOFuse Data::Dump qw( pp ); my $str = <<_BLA_; SECTION 1 bla bla bla SECTION 2 blabla blabla SECTION 3 bla _BLA_ my %hash = $str =~ /(SECTION \d+)\s*(.*?)(?=SECTION|$)/sg; pp \%hash; __DATA__ { "SECTION 1" => "bla bla\nbla\n", "SECTION 2" => "blabla\nblabla\n", "SECTION 3" => "bla", }
In reply to Re^2: Regex to array
by Eily
in thread Regex to array
by kepler
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |