in reply to Extra Space Issue

one approach that avoids package variables (and the magical package variables $a and $b) might be (UNTESTED):

my $grandtotal = 0; foreach my $row (@$array_ref) { my ($type, $total) = @$row; if ($type =~ m{\A \s* (?: A|B|C|D|W) \s* \z}xms) { $grandtotal += $total; } }