$text =~ s/(\W+)/$1->()/eg; # replace any nonwhitespace characters with the result of a function call #### %subs = ( bar => \&bar foo => \&foo do_something => \&do_something ); $text =~ s/(\W+)/$subs{$1}->() if defined $subs{$1}/eg; # only call from a list of specific subroutines