Weird Perl error using db2.

I have having a heck of a time figuring this out so any help is much appreciated.

Here is the code where it seems to be dying, I bolded the part it is complaining about:

$sth = $dbh->prepare( $query ) or die "error with query[$query]\n";
$sth->execute() or die "error executing query ...\n";
while( @row = $sth->fetchrow_array ) {
  undef $agent_id            ;
  undef $execution_id        ;
  undef $primary_auth_id     ;
  undef $client_pid          ;
  undef $client_platform     ;
  undef $client_dns          ;
  undef $appl_name           ;
  undef $user_id             ;
  undef $last_timestamp      ;
  undef $elapsed_hours       ;
  undef $elapsed_minutes     ;
  undef $elapsed_seconds     ;
  undef $chg_timestamp       ;
  undef $start_timestamp     ;
  undef $stop_timestamp      ;
  undef $query_cost_estimate ;
  undef $rows_read           ;
  undef $rows_written        ;
  undef $sql                 ;
  
  $agent_id             = rtrim($row[0]);
  $execution_id         = rtrim($row[1]);
  $primary_auth_id      = rtrim($row[2]);
  $client_pid           = rtrim($row[3]);
  $client_platform      = rtrim($row[4]);
  $client_dns           = rtrim($row[5]);
  $appl_name            = rtrim($row[6]);
  $user_id              = rtrim($row[7]);
  $last_timestamp       = $row[8];
  $elapsed_hours        = $row[9];
  $elapsed_minutes      = $row[10];
  $elapsed_seconds      = $row[11];
  $chg_timestamp        = $row[12];
  $start_timestamp      = $row[13];
  $stop_timestamp       = $row[14];
  $query_cost_estimate  = $row[15];
  $rows_read            = $row[16];
  $rows_written         = $row[17];
  $sql                  = $row[18];
  
  @cleandata = ($agent_id,$execution_id,$primary_auth_id,$client_pid,$client_platform,$client_dns,$appl_name,$user_id,$last_timestamp,$elapsed_hours,$elapsed_minutes,$elapsed_seconds,$chg_timestamp,$start_timestamp,$stop_timestamp,$query_cost_estimate,$rows_read,$rows_written,$sql);

#  if($sql !~ /SNAP_GET_APPL_INFO/ and $sql =~ /appdm\."?cp\_/i and $sql !~ /with\s+ur/i) {
  if($sql !~ /SNAP_GET_APPL_INFO/) {
    #
    # archive information into SQLite DB
    #
    $sqlitesql = qq|insert into sql_archive (agent_id,
                                            execution_id,
                                            primary_auth_id,
                                            client_pid,
                                            client_platform,
                                            client_dns,
                                            appl_name,
                                            user_id,
                                            last_timestamp,
                                            elapsed_hours,
                                            elapsed_minutes,
                                            elapsed_seconds,
                                            chg_timestamp,
                                            start_timestamp,
                                            stop_timestamp,
                                            query_cost_estimate,
                                            rows_read,
                                            rows_written,
                                            sql,
                                            datetime,
                                            epoch ) 
                                            values 
                                            (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)|; 
    $insert = $sqlitedbh->prepare($sqlitesql);
    @insertrow = @cleandata;
    push(@insertrow,$datetime);
    push(@insertrow,$epoch);
    $insert->execute(@insertrow);
  }
}
$sqlitedbh->commit();

#
# terminate db2 connection
#
$sth->finish();
$dbh->disconnect;

Here is the error it is throwing:

Fetch failed error -1 recorded: [IBM][CLI Driver][DB2/AIX64] SQL1042C  An unexpected system error occurred.  SQLSTATE=58004

    !! ERROR: -1042 '[IBM][CLI Driver][DB2/AIX64] SQL1042C  An unexpected system error occurred.  SQLSTATE=58004
' (err#0)
    <- fetchrow_array= ( ) [0 items] row-1 at sql_archiver.pl line 186
DBD::DB2::st fetchrow_array failed: [IBM][CLI Driver][DB2/AIX64] SQL1042C  An unexpected system error occurred.  SQLSTATE=58004

This was a previous administrator's script and I inherited the mess. It works fine on two other servers, I just can't figure out why it hates this one server. I have searched high and low, but everything I have found hasn't worked so far.

see notes on sql error 58004 then check the servers which are showing the issue ... there is most likely nothing wrong with the script other than to account for the differences found in the affected servers (i.e., command path, server load, os version, etc. ) ...