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"; }