Have you tried anything so far?? Please show us some code, maybe we can judge the problem better
Also, have you tried hacking up your algorithms though the use of $' and $` ? They will match the string on the left side and on the right side of a successfull regex-match. But they are pretty heavy performance wise, and perl doesnt get them unless you specifically state that you require (by using them). And if you use them once, Perl will make them available for all regex matches in your code, *thats* pretty heavy....