Have you considered the "replacement-option" of substr? Have a look at the following example, which replaces "fox":
my $text = "the quick brown fox likes jumping";
my $pos1 = index ($text, "fox");
my $length = 3;
substr( $text, $pos1, $length, "aligator");
print $text,"\n";