Algorithm Implementation/Strings/Longest common leading/trailing substring

This algorithm is a special case of the Longest Common Substring algorithm. The special case of leading (or trailing) gives a dramatic performance improvement - in my application roughly two orders of magnitude better.

Unfortunately I've only provided Perl at the moment, because thats what I need for my project! I'm hoping others who need this algorithm in other languages will record their implementation here.