while (my @row = $sth->fetchrow_array) { my $joined = join ',', @row[0..@row-1]; # do stuff }