in reply to proper way of matching multiple line patterns
If the format is line-based, it is often easier to do line-based processing, and add a bit extra logic that is not inside a regex.
For example you could use an approach like this:
use strict; use warnings; use Data::Dumper; sub use_the_data { my $d = shift; print Dumper $d; } my %d; while (<DATA>) { chomp; my ($key, $value) = split /:\s*/; if (%d && $key eq 'Name') { use_the_data \%d; # reset %d %d = ($key => $value); } else { $d{$key} = $value } } use_the_data \%d; __DATA__ Name: 123 Phone: foo Name: blubb Phone: blah
|
|---|