# assuming $sth is your SQL statement under DBI $sth->execute(); my @columns; for( @{$sth->{NAME}} ) { push @columns, $_; } while( my $r = $sth->fetchrow_arrayref ) { my $index = 0; for( @$r ) { $columns[$index++] .= "|$_"; } } print "$_\n" for @columns;