@keys = @{$sth2->{NAME}}; print join "\t", @keys; print "\r"; while ($record = $sth->fetchrow_hashref()) { print join "\t", map { $record->{$_} } @keys; print "\r"; }