I prefer the OP's approach. Functions should return their results through the return rather than through a reference. I believe that most of his additional code is code that he added to debug the problem himself before he posted. If so, he should be commended. Your use of Dumper and your attention to scope are details he should learn.