in reply to Re: How do I match the closest of repeated strings?in thread How do I match the closest of repeated strings?
But it can be adapted, of course:
m{ ( ^abc$ (?:(?!^(?:def|abc)$).)* ^def$ ) }smx [download]