open ERRS, ">error.log" or die $!; while( ... ) { my ( ... ) =~ m/ ... /x; if ( $authors ) { # output as desired } else { print ERRS "$_\n"; } } close ERRS;