use strict; use warnings; package main{ use Data::Dumper; our $marshall_data = \do{my $file_simulator}; my @data1 = qw(one won); my @data2 = qw(two too to); push @data2, \@data1; # Add recursive elements push @data1, \@data2; open my $FH, '>', $marshall_data; print {$FH} Data::Dumper->Dump( # Marshall the data [ \@data1, \@data2 ], [qw(*data1 *data2)] ); close $FH; Testing::recursive_data(\@data1, \@data2); # Both tests pass } package Other{ my @data1; my @data2; open my $FH, '<', $main::marshall_data; my $string = do {local $/ = undef; <$FH>}; # Slurp the string close $FH; # print $string, "\n"; eval $string; # Restore content of arrays die "Marshalling Failed: $@\n" if $@; Testing::recursive_data(\@data1, \@data2); # Second test fails } package Testing{ use Scalar::Util qw( refaddr ); use Test::Simple tests => 4; sub recursive_data{ my ($data1_ref, $data2_ref) = @_; ok( refaddr($data1_ref) == refaddr($data2_ref->[3]), '$data2[3] refers to @data1' ); ok( refaddr($data2_ref) == refaddr($data1_ref->[2]), '$data1[2] refers to @data2' ); } }