my $str = 'nodes0005'; my @chars = split //, $str; @chars[3,4] = ("A", "B"); my $out = join "", @chars;