$school_number = -1; # no schools yet ... foreach my $line1(@x){ $school_number++; # change the data index ($school[$school_number]{school}, $school[$school_number]{addr}, ...