in reply to fixed length string

How about one line, ops, one command?! ;-P
$s = sprintf("%-5.5s" , $s) ;

Graciliano M. P.
"Creativity is the expression of the liberty".