<p>I have a string of arbitrary length, and starting at position p0, I need to find the first occurrence of one of three 3-letter patterns.</p>

<p>Assume the string contain only letters. I need to find the count of triplets starting at position p0 and jumping forward in triplets until the first occurrence of either 'aaa' or 'bbb' or 'ccc'.</p>

<p>Is this even possible using just a regex?</p>

```
```
$string=~/^   # from the start of the string
            (?:.{$p0}) # skip (don't capture) "$p0" occurrences of any character
            (?:...)*?  # skip 3 characters at a time,
                       # as few times as possible (non-greedy)
            (aaa|bbb|ccc) # capture aaa or bbb or ccc as $1
         /x;
```
```
(Assuming p0 is 0-based).
Of course, it's probably more efficient to use substr on the string to skip forward:
```
```
substr($string, $p0)=~/^(?:...)*?(aaa|bbb|ccc)/;
```
```