#!/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;