Q:

How can I process a file two lines at a time in Perl?

I have a signal file with each line beginning with 0 or 1.
If I have 1 followed by 0 in the next line, then I need to process the 0 signal line.
>#Sample File

>0

>0

>1

>0 (process line)

>0

>1

>0 (process line)

my code

 OUTER : while (<F>) {
   if($_=~/1/){
     my $a = <F>
     process_line($a) if ($a=~/0/);
     next OUTER if ($a=~/1/);
   }

The file is huge, so I don't want to slurp.

A:

Something like:
#!/usr/bin/perl

use strict;
use warnings;
my $prevLine = "";

sub processline {
    my $line = shift;
    $line =~ s@^0 @@;
    print $line;
}

while (<DATA>) {
    if ($_ =~ /^0/ && $prevline =~ /^1/) {
        processline($_);
    }
    $prevLine = $_;
}

__DATA__
0
0
1
0 (process line)
0
1
0 (process line)

Output
(process line)
(process line)

