in reply to Function call in a regular expression

Perl provides the (??{}) (This is a "postponed" regular subexpression) construct in regular expressions for the purpose you mention. For example:
$text =~ s|(??{chr 231})|c|gise;
There is more information about the construct in perldoc perlre.

update: Note I am answering the question of:

I'd like to be able to call a function in the matching portion of substitution expression.

(though there are better solutions that do the same thing as the OP's example below).

-enlil

Replies are listed 'Best First'.
Re: Re: Function call in a regular expression
by sauoq (Abbot) on Jul 31, 2003 at 22:22 UTC

    Be aware that this is an experimental feature. One of the other ways to do it might be more appropriate for production code.

    -sauoq
    "My two cents aren't worth a dime.";
    
Re: Re: Function call in a regular expression
by diotalevi (Canon) on Jul 31, 2003 at 22:40 UTC

    Update: Oops, I misread Enlil's (??{}) as (?{}) which is very different. His original code works, it just isn't a great way to write that. Better to write it directly as \xe7.

    No, no this is wrong. (?{}) is zero width and is always true. That's no help to the person who just wants to get the character #231 into their regex. Some other nice monks noticed that you could write it in hex form \xe7 or BrowserUK's verbose (and slightly slower) @{[ chr 231 ]}.