Your pattern (/^\w\w.+(\w\w).+(\d+).+(\w\w)/sg), which "should only match the first paragraph", actually matches them all (except the one that's only "1").
/^\w\w.+(\w\w).+(\d+).+(\w\w)/sg
h i\n h i \n 234 \n h i
/^\w\w.+(\w\w).+ (\d+) .+(\w\w)/xsg
h o i\ns d fsdfsdf 23423\n h i
/^\w\w.+(\w\w).+(\d+).+(\w\w)/sg
h i \n h i \n 1 2 3 4
Try just enumerating the paragraphs:
sub slurpie {
local $/ = '';
my $n = 1;
while (<DATA>) {
printf "*** paragraph %d ***\n", $n++;
print;
}
}
slurpie();
__END__
*** paragraph 1 ***
hi
hi
234
hi
*** paragraph 2 ***
hoi
sdfsdfsdf23423
hi
*** paragraph 3 ***
hi
hi
1234
*** paragraph 4 ***
1