#get rid of the bad doct characteres if ($ARRGH =~ /ibZtfacr008_chg<\/className>/) { $ARRGH =~ s/Customer trans\.(.*)<\/doct>/Customer trans\.<\/doct>/g; } #### ibZtfacr008_chg foo bar Customer trans. garbage bar foo Customer trans. garbage