while (<>) { if (/^level (\d+)/) { $i = $1; } else { $array .= $_; } }