After you execute the statement, the statement handle should contain a NAME attribute. This is a reference to an array containing the names of the columns returned. $sth->{NAME}[$i] will give you the name of column $i. See perldoc DBI.