http://www.perlmonks.org?node_id=1031662


in reply to Selecting HL7 Transactions

I would suggest using regexes only to pull individual segments out of the transaction string.
$PV1segment = ($transaction =~ /PV1.+?~/;
assuming ~ is the segment terminator. Then, use split to break the segments into arrays. It is much easier than dealing with regexes, and takes advantage of the delimited structure of the data.