I wrote a simple program for something similar once. Seemed like you needed to account for inexact matches, if it was a real world and not an academic problem.
You might want to look at the CPAN module String::Approx. It aint a speed demon, but it seemed to work.