* tta/perl/Texinfo/ManipulateTree.pm
($destroyed_objects_refcount_text): rename
$destroyed_objects_refcount_target as
$destroyed_objects_refcount_text.  Update
$destroyed_objects_refcount_text when $destroyed_objects_refcount
changes.
diff --git a/ChangeLog b/ChangeLog
index b1931c8..406f1f9 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,14 @@
 2025-08-20 Patrice Dumas  <pertusus@free.fr>
 
+	* tta/perl/Texinfo/ManipulateTree.pm
+	($destroyed_objects_refcount_text): rename
+	$destroyed_objects_refcount_target as
+	$destroyed_objects_refcount_text.  Update
+	$destroyed_objects_refcount_text when $destroyed_objects_refcount
+	changes.
+
+2025-08-20 Patrice Dumas  <pertusus@free.fr>
+
 	* tta/swig/perl/Makefile.am (perl_texinfo_wrap.c),
 	tta/swig/python/Makefile.am (python_texinfo_wrap.c): expand $< in
 	non-suffix rules for BSD make.
diff --git a/tta/perl/Texinfo/ManipulateTree.pm b/tta/perl/Texinfo/ManipulateTree.pm
index cc2282f..4af0ddb 100644
--- a/tta/perl/Texinfo/ManipulateTree.pm
+++ b/tta/perl/Texinfo/ManipulateTree.pm
@@ -118,17 +118,20 @@
 
 my $destroyed_objects_refcount = 2;
 # used in messages
-my $destroyed_objects_refcount_target = $destroyed_objects_refcount;
+my $destroyed_objects_refcount_text = $destroyed_objects_refcount;
 my $no_XS_objects_refcount;
 if (Texinfo::XSLoader::XS_parser_enabled()) {
   # a reference in C too
   $destroyed_objects_refcount++;
+
   if (!$XS_structuring) {
     # transformations may create elements in pure Perl only when
     # structuring is not done with XS extensions.
     $no_XS_objects_refcount = $destroyed_objects_refcount -1;
-    $destroyed_objects_refcount_target
+    $destroyed_objects_refcount_text
        = "$destroyed_objects_refcount or $no_XS_objects_refcount";
+  } else {
+    $destroyed_objects_refcount_text = $destroyed_objects_refcount;
   }
 }
 my $element_SV_target_count = 1;
@@ -610,7 +613,7 @@
     # plus possibly one count owned by the C code
     #if (1) {
     #Devel::Peek::Dump($element);
-    if ($reference_count != 1
+    if ($reference_count != $element_SV_target_count
         or ($object_count != $destroyed_objects_refcount
             and !(defined($no_XS_objects_refcount)
                   and $object_count == $no_XS_objects_refcount))) {
@@ -627,7 +630,7 @@
           $findref_info = Devel::FindRef::track($element)."\n";
         }
         my $message = "Element refcount ($reference_count, $object_count) != ".
-               "($element_SV_target_count, $destroyed_objects_refcount_target)";
+               "($element_SV_target_count, $destroyed_objects_refcount_text)";
         warn "You found a bug: $message for $element\n\n".
         Texinfo::ManipulateTree::element_print_details($element)."\n".
          $findref_info;