while (!$recordset->eof) { # code to set scalars equal to fields in $recordset $hashofrecordset{$id} = { foo => $foo, bar => $bar, baz => $baz, }; } #### foreach $outerkey ( sort keys %hashofrecordset ) { print "\n$hashofrecordset{$outerkey}\n"; foreach $innerkey ( sort keys %{ $hashofrecordset{$outerkey} }) { print "\t$hashofrecordset{$outerkey}{$innerkey}\n"; } print "\n"; }