my $section = ''; #remember the last section label we encountered foreach (@m) { if (/^Dig No\s:\s(\w*)\s*Prior:\s*([0-9]*)\s*Digstrt:\s*([0-9]{ +2}\/[0-9]{2}\/[0-9]{2})\s*Time:\s*([0-9]{2}:[0-9]{2})/) { $section = 'DIGTIME'; $m{'DIG_NO' } = $1; $m{'PRIORITY'} = $2; $m{'DIGDATE' } = $3; $m{'DIGTIME' } = $4; } elsif (/^Address\s*:\s*(.*)Subdivsn/) { $section = 'ADDRESS'; $m{'ADDRESS' } = $1; } elsif (/^Remarks\s*:\s*(.*)/ ) { $section = 'REMARKS'; $m{'REMARKS' } = $1; } elsif (/^\s*:\s*(.+?)\s*/) { $m{$section} .= $1; } }