I know that it is easy to match anything except a given character using a regular expression.
$text = \"ab ac ad\";
$text =~ s/[^c]*//g; # Match anything, except
The following solves the question as understood in the second sense described in Bart K. comment:
>> $text='ab ac ad';
>> $text =~ s/(ac)|./\1/g;
>> print $text;
ac
Also, 'abacadac'
-> 'acac'
It should be noted though that in most practical applications negative lookaheads prove to be more useful than this approach.