Wow, this smells like homework. :)
Anyway, you could split the string into an array of single characteres and print off each element within a loop adding a "\n" every five characters.
You could use substr and print five character slices plus a "\n" until you get to the end of the string.
You could make a format, but that's not as fun IMHO.