in reply to keep database records after select

Presumably you have

@$arrayRef = (); while (my $row = $sth->fetch()) { push @$arrayRef, $row; }

To quote from the docs for fetch_arrayref,

Note that the same array reference is returned for each fetch, so don't store the reference and then use it after a later fetch. Also, the elements of the array are also reused for each row, so take care if you want to take a reference to an element. See also "bind_columns".

Replace it with

@$arrayRef = (); while (my $row = $sth->fetch()) { push @$arrayRef, [ @$row ]; # Make a copy. }

or with

@$arrayRef = @{ $dbh->selectall_arrayref($stmt_or_sth) };

Updated to use OP's $arrayRef instead of a new variable.