toothedsword has asked for the wisdom of the Perl Monks concerning the following question:

can regex contains function? I want convert the first character of words upcase. The code below does not work.

#!/usr/bin/env perl my $t = ' aa bb cc'; $t =~ s/(\s)(\w)/${1}uc($2)/g; print($t);

Replies are listed 'Best First'.
Re: can regex contains function?
by choroba (Archbishop) on Jun 19, 2020 at 07:49 UTC
    > can regex contains function?

    Yes, it can. That's what /e is for.

    $t =~ s/(?<=\s)(.)/uc $1/ge;

    But you don't need it here:

    $t =~ s/(?<=\s)(.)/\U$1/g;

    map{substr$_->[0],$_->[1]||0,1}[\*||{},3],[[]],[ref qr-1,-,-1],[{}],[sub{}^*ARGV,3]
Re: can regex contains function?
by soonix (Canon) on Jun 19, 2020 at 07:29 UTC
      Thank you so much! Now I know how to solve this specific question. But do you know can I instert a function to the regex?

        If I understand your question, the first responder answered it: use the /e qualifier.