while ($newline = ){ if ($newline = /^>/) { if ($i == $number) { #initialize a bunch of stuff and continue } else { $i++; #and then go back to whatever the last line that =~ /^>/ and go again } } $stuff = $newline; &play_with($stuff); }