in reply to YAML and perl
You don't show the code that is problematic, so it is somewhat hard to give you concrete advice.
I recommend the following approach: