Thank you Jeffa!
I shall try this out and adapt it for my full problem later today but this is so sweet. Someone else pointed me at perldoc.perl.org/perldsc.html and perldoc.perl.org/perllol.htm, which I was reading but finding hard to turn into a working example. They should however allow me to fully understand your reply.