use strict; use warnings; use DBI; use Term::ReadKey; # use mode 2 'noecho' to ask for the connection pwd, then revert to normal my $dbh = init_DB_connection; my $first_step_result = do_first_step; # https://metacpan.org/pod/DBI#do returns NRows, undef or -1 if ( !defined $first_step_result ){ ... } # report errors and exit elsif ( -1 == $first_step_result ){ ... } # perhaps this is a success in case of create table, dunno, execute second_step elsif ( $first_step_result > 0 ){ ... } # $first_step_result rows affected else { ... } # got unexpected $first_step_result sub init_DB_connection { ... } # return $dbh on success, exit if errors sub do_first_step { ... } ...