Strings In Depth16 / 18
Up next

Replace with 4-arg substr

use strict;
use warnings;
use feature 'say';

my $s = "hello world";
# the 4-arg form swaps in new text and returns the old
my $old = substr($s, 0, 5, "howdy");
say "$old -> $s";
What you're solving

substr can overwrite a slice