$sth->execute() or die "Error executing [$sqlcmd] : " . $dbh->errstr; $end_fetch = 0; do { if (! $end_fetch) { ($key_col, $col1, $col2, $col3) = $sth->fetchrow_array; if (! defined $key_col) { $end_fetch = 1; } } ... } while ($some_condition);