I guess this would be a good place for assertions. An assertion is a piece of Perl code embedded in the regex, which says that a match may or may not succeed.
Now the current (perl5) syntax for a regex assertion is very awkward. This will do it:
/(?(?{NOTCOND})(?!))/
NOTCOND is perl code producing a true when you want the assertion to
fail, because only in that case an attempt to match the regex snippet /(?!)/ is made, and this is a lookahead that never matches.
So, you can try this:
my $i = 0;
s/ab(?(?{++$i>5})(?!))/cd/g;
This will indeed stop matching after the fifth match, producing the desired result; but it will not stop trying: it will go through the whole string, and if your string contains 50 substrings "ab", then the assertion code will be called 50 times. So for long strings, it won't be too efficient.