/bin/cat $1 | perl -00 -pe 's/ABC(.*?)XYZ/\[DATA\]\n/s' #### 123 ABC 123 abc XYZ hi la #### 123 [DATA] la #### 123 [DATA] hi la