Don't use scan on a string.

Also, be more explicit with variable names, rather than re-use "output"
within the loop.