foreach(@class) { ($id, $name, $credits) = split(/,/, $_); $x=0; while ($clen > $x) { if ($course[$x] eq $id) { $z++; } $x++; } }