It seems like you're writing your arrays as array references just so you can avoid creating a reference out of a non-reference.
You have:
foreach $line (@lines){
chomp $line;
$count++;
next unless $count; # skip header in csv
my $row;
@$row = split(/,/, $line );
push @$sheet2 , $row;
}
But if you ask me, it'd be tons more clear if you did this:
my @sheet2 = ()
# ....
foreach $line (@lines){
chomp $line;
$count++;
next unless $count; # skip header in csv
my @row = ();
@row = split(/,/, $line );
push @sheet2 , \@row;
}
Another example is:
@$sheet2 = ();
Should be:
@sheet2 = ();
or
$sheet2 = [];
It seems to me you're conflating scalars, arrays, and references. Cleaning up the code and being consistent will go a long way in dispelling your confusion.