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


in reply to Adding formatting to a string

How about this?
my $string = "ABCDEFGH"; $string = sprintf("%.4s-%s", $string,substr($string,4,4));
Awkward, maybe, but I have tried it and it works.