# Use LIMIT 1 to keep the database from working # too hard my $sql = q(SELECT * FROM table LIMIT 1); my $sth = $dbh->prepare($sql) or die . . . ; $sth->execute(); my @col_names = keys %{ $sth->fetchrow_hashref }; $sth->finish();