Another way you may find quicker depending on how large your input string is is to use substr to nibble N chars at a time and then use the next pos to grab the next group of chars. This should be fairly speedy with little of the overhead of the above.