in reply to regex help ...

How about this attempt?
#!/usr/local/bin/perl -w use strict; my $file; { local $/; $file = <DATA>; } print "$_\n" for $file =~ m/loop\s*(warn.*)\s*endloop/mg; __DATA__ begin loop warn('xxx'); endloop; loop null; endloop; loop warn('rrr'); endloop; begin warn('yyy'); end; warn('zzz'); end;
And the output is -
warn('xxx'); warn('rrr');