$dbh->do("INSERT INTO tbl VALUES(NULL,'foo','bar')"); #### my $ref = $dbh->selectcol_arrayref( "SELECT MAX(LineID) FROM tbl" ); my $LineID = $$ref_booking[0]; #### my $ref = $dbh->selectcol_arrayref( "SELECT LAST_INSERT_ID() FROM tbl "); #### $dbh->{AutoCommit} = 0; # enable transactions, if possible $dbh->{RaiseError} = 1; eval { $dbh->do("INSERT INTO tbl VALUES(NULL,'foo','bar')"); my $ref = $dbh->selectcol_arrayref( "SELECT MAX(LineID) FROM tbl" ); $dbh->commit; # commit the changes if we get this far }; if ($@) { warn "Transaction aborted because $@"; $dbh->rollback; # undo the incomplete changes # add other application on-error-clean-up code here }