in reply to Formatting and write help
It looks like you'll have a working solution with ikegami's help, but if you're in the mood to explore a different way of accomplishing your task, you might look at Perl6::Form.
In Section
Seekers of Perl Wisdom