in reply to matching several lines

Capture the results of the match in an array.

my @messages = /AAAAAA(.*?)BBBBBB/sgm; foreach (@messages) { print "$_\n"; }