while (<$IN>) { next if /^\s*$/; # remove empty lines next if /^\s*#/; # remove comments next if /ORA/i; # remove lines with Oracle warnings and errors next unless some_condition($_); last if /File processed/; # ... now do the actual processing of useful lines }