This is great. It certainly seems to work. I'll have to expand it out to handle the full problem but it looks like a good solution.
I actually coded up a different solution using hashes that works well. If your interested, you can look at the production code on my scratchpad
here.
Thanks for your help
PJ
use strict; use warnings; use diagnostics; (if needed)