my $string = "foo bar baz"; my $replacement = "moo"; # This will print "foo moo baz" print substr($string, 4, 3, $replacement), "\n";