my $dbh = DBI->connect("DBI:mysql:database=mydatabase;host=localhost", "name", "password", {'RaiseError' => 1}); $SQLStatement = "SELECT etc..." $sel = $dbh->prepare( $SQLStatement ); $sel->execute() || die "Could not open database"; while( ($somedata) = $sel->fetchrow_array ) {#actions...}