my $line = <$fileHandler>; while(1) { # keep looping until I say so my $nextLine = <$fileHandler>; if ($line =~ m/>/ || !defined $nextLine) { ### Do the stuff } ### Do any other stuff; last unless defined $nextLine; $line = $nextLine; }