my $string = "ABCDEFGH"; $string = sprintf("%.4s-%s", $string,substr($string,4,4));