{ my @output; local $dbh->{odbc_err_handler} = sub { .... push @output, $print_statement; ... }; while ($sth->{odbc_more_results}) { while (my $data = $sth->fetchrow_array()) { ... push @output, (join("|", @$data) . "\n"); } } }