Change print to return, and it works.
use warnings; use strict; my $string = "this is a test \$placeholder"; $string =~ s/\$placeholder/test_sub()/e; print $string; sub test_sub { return "hello there"; }
If you really need to capture the output of what a sub prints, that's a whole other problem. I was doing something like that in Use of uninitialized value in open second time but not first., and there's more discussion with it about other ways to do it.
In reply to Re^3: Regex to replace $vars with subroutine
by kyle
in thread Regex to replace $vars with subroutine
by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |