my %children = ( 0 => [1,21], 1 => [2,10], 2 => [3,4], 3 => [5,7], 7 => [8,9], 4 => [6], 10 => [11,14], 11 => [12,13,20], 14 => [15,16,17,18,19] ); my %obj = ( 1 => "Food", 2 => "Beans and Nuts", 3 => "Beans", 4 => "Nuts", 5 => "Black Beans", 6 => "Pecans", 7 => "Kidney Beans", 8 => "Red Kidney Beans", 9 => "Black Kidney Beans", 10 => "Dairy", 11 => "Beverages", 12 => "Whole Milk", 13 => "Skim Milk", 14 => "Cheeses", 15 => "Cheddar", 16 => "Stilton", 17 => "Swiss", 18 => "Gouda", 19 => "Muenster", 20 => "Coffee Milk", 21 => "Not Food!", ); my @out = ( [1,'Food'],[2,'Beans and Nuts'],[3,'Beans'],[4,'Black Beans'],[4,'Kidney Beans'],[5,'Red Kiney Beans'],[5,'Black Kidney Beans'],[3,'Nuts'],[4,'Pecans'],[2,'Dairy'],[3,'Beverages'],[4,'Whole Milk'],[4,'Skim Milk'], [4,'Coffee Milk'], [3,'Cheeses'], [4,'Cheddar'],[4,'Stilton'],[4,'Swiss'],[4,'Gouda'],[4,'Muenster'],[1,'Not Food!']);