my $new = 'blah'; my $string = 'asdfjkjl'; my $find = '(asd)'; my $replace = '$1' . $new; replace ($string, $find, $replace); sub replace { my $string = shift; my $left = shift; my $replace = shift; $string =~ s/$left/$replace/e; print $string; }