One occasion was a bunch of build packaging shell scripts, part of a multi-phase build system, these things had grown over the years, there was one script for each hardware type supported and as each new machine type was added someone (usually a different person each time, some of whom inevitably left) would copy the entire script, bodge some changes in and check it in, and they ended up with a couple of thousand lines of terrible code that no-one understood or knew the history of, and it became unmaintainable. I'm sure everyone here is familiar with this kind of story. They asked me to look at it, I designed some xml to describe the targets and reduced the thousands of lines to about 300 lines of perl based around an xml parser, and deleted all of the original code. Thereafter the replacement perl script remained unchanged and each new machine type merely added a new descriptor to the xml, which radically simplified and speeded up the whole process of adding a new hardware type. So sometimes doing a rewrite works out really well. Of course in that instance it helped that it was a fairly self-contained piece of work without a lot of linkage to other code.