open (FILE '; close FILE; foreach my $line (@file) { exit if $line =~ /error.*error/; # Process here }