in reply to Parsing and editing a configuration file

I'd just be lazy and use a flip-flop.

#!/usr/bin/perl -n if(/RECORD\s+"(?:ABC|XYZ)"/ ... /END_VIEW/) { s/^\s*field\s+\K"region"/"LOCATION"/i; s/^\s*field\s+\K"rubbish"/"TRASH"/i; } print;

Having the structure inline, I'd just split then into @lines and say for(@lines) { ... }

More matching pairs can be introduced with nested if-blocks of the same form - if (m{...} ... m{...}) { ... }

perl -le'print map{pack c,($-++?1:13)+ord}split//,ESEL'