my $state = 0; while(<>) { if($state == 0 && /CPU/) { $state = 1; } elsif($state == 1 && ?vendor?) { $state = 2; # YIPPEE! process the data } else { $state = 0; # fail } } continue { if(eof) { # do NOT put () on eof - RTFM close ARGV; # resets $. to start at 0 for the next file $state = 0; reset; } }