while (my @a = grep defined, map scalar <$fd>, 1 .. 6) { # do whatever you want with @a, which has 6 lines }