Fletch has given you a nice hint to get you started.
Please understand that Perl Monks is not a code writing service. Quoting from Gramps' reply to one of many similar recent questions:
I know you are hoping that we might just write the whole thing for you, but you should at least show some effort. Meet us part way by showing a first attempt at solving the problem with comments indicating where you can't figure stuff out.
See also: How do I post a question effectively?
In reply to Re: Find common substrings
by eyepopslikeamosquito
in thread Find common substrings
by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |