You could just use regular expressions to blindly perform the preg_replace() you want without performing the check first.
As with other topics, I will give you an example of how to do this in a cygwin bash shell and leave it up to you to understand the principle behind the example and adapt it to your specific situation.
#
# echo "Re: Re: Re: Re: Re: Re: Subject" | sed 's#Re: .*Re: #Re: #'
Re: Subject
#
# echo "Re: Subject" | sed 's#Re: .*Re: #Re: #'
Re: Subject
#
# echo "Subject" | sed 's#Re: .*Re: #Re: #'
Subject
#
Note that here it is the greedy behavior of regular expression wildcards that takes hold of the entire repetitive Re: string.
Also, remember that preg_replace() is always global (s###g) so you only need one iteration for this function. Putting it in a while loop could cause serious performance problems.
In this particular case you do need regular expression power, but if you don't - and you just want to search and replace - you should use str_replace instead.
Comment/Reply (w/o sign-up)