while (<>) { exit if /error.*error/; # do whatever you want to do... }