# Text wrapped to fit in the screen my $text = "0011222STRUCTdata..........6ab.." . "02121STRUCTdata.........." . "021232STRUCTdata......" . "02342STRUCTdata......"; my @matches = $text =~ m/(\d+) # First match some numbers STRUCT # Then the STRUCT keyword (.+?) # Then the data, that have to # be followed by (?= # (look-ahead assertion) (?:\d+STRUCT # - numbers and 'STRUCT' | # or $ # - end of line ) )/xg; # Then remove the first two matches that is first numbers and # first data @matches = splice @matches, 2; { local $, = ","; print @matches, "\n"; }