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


in reply to General Question on parsing a variable

You will find it easier to access the records if you read them into a suitable data structure first. In Perl, that usually means a hash:

my %hash; $hash{$1} = $2 while $var =~ /storeID = (\d+)\s+(.*?)end/gs;

Then you can search like this:

my $criterion = ...; print "storeID = $_\n", $hash{$_} for grep { $hash{$_} =~ /$criterion/ + } keys %hash;

Hope that helps,

Athanasius <°(((><contra mundum Iustus alius egestas vitae, eros Piratica,