in reply to Re^2: Regex to replace $vars with subroutine
in thread Regex to replace $vars with subroutine

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.