{ while (my ($location, $devices) = each %devicecount) { foreach my $line (@workingdata) { my @Fld = split /,/, $line; if (/${location}TEXT/) { $somevar += $Fld[11]; $someothervar += $Fld[12] } } printf OUTPUT "some stuff from the info we gathered"; } }