foreach my $sql (@sql) { unless ($sth=run_sql($sql)){ die "Failed in processing \"".$sql."\"\n"; } } #Use them like this... my $result = $sth->fetchall_arrayref; #### # #run_sql # subroutine that does all of the work # sub run_sql{ my $sql = shift; my $sth = $dbh->prepare($sql); if (!$sth) { die "Error:" . $dbh->errstr ." while preparing ".$sql."\n"; } if (!$sth->execute) { die "Error:" . $sth->errstr ." while executing ".$sql."\n"; } return $sth; } # run_sql