You need to add an /s modifier to the regex:
#! perl use strict; use warnings; our $/ = ''; while (my $currentrecord = <DATA>) { if ($currentrecord =~ m/^field2(.*)\nfield3/msi) { my $field2data = $1; print "Found \$field2data = $field2data\n"; } } __DATA__ record 1: field1: data 1 monday field2: data 2 monday field3: data 3 monday record 2: field1: data 1 tuesday field2: data 2 tuesday tuesday details line 1 tuesday details line 2 field3: data 3 tuesday
Output:
19:07 >perl 692_SoPW.pl Found $field2data = : data 2 monday Found $field2data = : data 2 tuesday tuesday details line 1 tuesday details line 2 19:08 >
See perlre#Modifiers.
Hope that helps,
| Athanasius <°(((>< contra mundum | Iustus alius egestas vitae, eros Piratica, |
In reply to Re: Regex to fix up records, some multiline fields, some not
by Athanasius
in thread Regex to fix up records, some multiline fields, some not
by butchie3980
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |