in reply to extract the Column names of a table

See the "NAME" and "NAME_lc" attribute of the $sth as described in DBI. For example, after reading any row (or all rows) of your result, you can say:
my @col_names = @{$sth->{NAME}};
You might even get the names before the first result—depends on the database.