perl regex for extracting multiline blocks

perl, regex

Solution

This should do the trick. Beginning of next \d\d:\d\d is treated as block end.

use strict;

my $Str = '00:00 stuff
00:01 more stuff
multi line
  and going
00:02 still 
    have
00:03 still 
    have' ;

my @Blocks = ($Str =~ m#(\d\d:\d\d.+?(?:(?=\d\d:\d\d)|$))#gs);

print join "--\n", @Blocks;

Problem

I have text like this: ``` 00:00 stuff 00:01 more stuff multi line and going 00:02 still have ``` So, I don't have a block end, just a new block start. I want to recursively get all blocks: ``` 1 = 00:00 stuff 2 = 00:01 more stuff multi line and going ``` etc The bellow code only gives me this: ``` $VAR1 = '00:00'; $VAR2 = ''; $VAR3 = '00:01'; $VAR4 = ''; $VAR5 = '00:02'; $VAR6 = ''; ``` What am I doing wrong? ``` my $text = '00:00 stuff 00:01 more stuff multi line and going 00:02 still have '; my @array = $text =~ m/^([0-9]{2}:[0-9]{2})(.*?)/gms; print Dumper(@array); ```

Original source