Well, you might make do with one copy of the loop body, at the expense of a hairy loop condition like: <code>
const char *tmp;
compiled_regex * pcre = IsARealRegex(regex) ? RegexCompile(regex) : NULL;
size_t reglen = strlen(regex);
while ((count < max) && (pcre ? RegexMatch(pcre, sp, &start, &end) : (tmp = strstr(sp, regex), start = tmp ? tmp - sp : strlen(sp), stop = tmp ? start + reglen : start, tmp)))
</code> or you could write a little static local function to call, that packages the tmp-part of the outer ?: in this.