You can pass in a callback function to the third argument of the replace function
public function upCase( Any pattern, Any position, Any orig ) {
return uCase( pattern );
}
result = replace( "A man a plan a canal.", "an", upCase, "ALL" );
writeOutput( result );
Result: A mAN a plAN a cANal.
Example with start argument (Replace lowercase 'o' with uppercase 'O' from the third position)
You can pass position to start searching in the string