http://www.perlmonks.org?node_id=291981


in reply to How do I insert characters at certain positions in a string?

If you do not want to replace the character you can set the substring length to zero.
my $padded = 'ABCDEFG'; substr($padded, 2, 0) = '1'; substr($padded, 1, 0) = '2';
This will result in 'A2B1CDEFG'