How to set a flag and search for the last <p> tag in a file and substitute with <con>