while (my ($location, $devices) = each %devicecount) { # Test the above variables print "Loc: [[[$location]]]\tDev: [[[$devices]]]\n"; foreach my $line (@workingdata) { ...