in reply to I need to regex multiple lines

Comment: The end of string \Z in $capture is needed because of the lookahead(?=) in the regex. Without it it wouldn't match the last entry.
use strict;
use warnings;
use File::Slurp;

my $wholefile = read_file('data.txt');
my $capture = qr{(LENGTH|SUBJECT|COMMENT|\Z)};

while ($wholefile =~ m{^$capture:(.*?)(?=$capture)}smgcx) { my ($type , $data) = ($1 , $2); print "Type: $type\n"; print "Data: $data\n"; }