It might make it a lot easier for others to help you if you provide a self-contained example for others to run to duplicate the problem you are having. You should populate your @tmp2 array for us. Then show the output you get along with the output you expect.