in reply to replace a line when regex match...

In general, this will do it:

perl -i.bak -pe 's/before/after/' filename
This changes your file in place, and puts a back up in filename.bak. The only thing left is specifying the s/// expression, but from your post I can't figure out exactly what you want. So, exactly, what should the lines to be replaced look like, and what should the replacement look like?

the lowliest monk