while (my @rows = $sth->fetchrow_array() ) { return join '', map {sprintf $fmt, @$_ } \@headers, \@rows; } $sth->finish; #### my $result = sprintf $fmt, @headers; while ( my @rows = $sth->fetchrow_array() ) { $result .= sprintf $fmt, @rows; } $sth->finish; return $result;