in reply to A format to "print" to variable?

If sprintf doesn't do what you need, I recommend Text::Reform and Text::Autoformat.