my $sub_re = qr/ (\d+ (?:\sPSI)?) (?:\s*\n)+ /x; $text =~ s/ (.+?) (?:\s*\n)+ $sub_re $sub_re $sub_re $sub_re /push @r, [ $1, $2, $3, $4, $5 ]/esgx;