__DATA__ XXXXXXABCDXXXXXXXX XX**XXX!!!X**AB*!C*DXX*!!!XXX**XXX #### 10 characters added XXXXXXABCD**!!!***!*XX*!!!XXX**XXX #### use strict; use warnings; my $match = 'ABCD'; while () { my $org = $_; defined (my $mutated = ) or die "Missing edited line"; my $segment = substr $mutated, 0, index ($mutated, substr $match, 3, 1) + 1; my $suffix = substr $mutated, index ($mutated, substr $match, 3, 1) + 1; (my $pInsert = $segment) =~ tr/*!//cd; (my $pSegment = $segment) =~ tr/*!//d; print length ($pInsert) . " characters added\n"; print "$pSegment$pInsert$suffix\n"; } __DATA__ XXXXXXABCDXXXXXXXX XX**XXX!!!X**AB*!C*DXX*!!!XXX**XXX