:- perl_substitute(+String, +PerlSubstitutionExpr, -ResultString).
We assume you are familiar with the syntax of Perl substitution expressions. Here we just give an example of what kind of things are possible:
:- perl_substitute('this is fun', 's/(this) (is)(.*)/\2 \1\3?/', Str). Str=is this fun?