Perl equivalent php preg_callback

Do we have the equivalent of preg_callback in Perl?

Suppose I want to match something and replace it with the return value of a function called with the matching thing.

+7
php regex perl
source share
1 answer

Use s///e - evaluation modifier, and you can put arbitrary Perl codes in the second part.

 $x = "this is a test"; $x =~ s/(test)/reverse($1)/eg; print $x; //this is a tset 

ref: http://perldoc.perl.org/perlretut.html#Search-and-replace

+16
source share

All Articles