while (my $line = ) { chomp $line; # Do stuff here } #### while () { # Skip commented-out lines (or whatever else you want to do) next if /^#/; # Don't chomp unless we know we're going to use the line chomp; if (/SOME REGEX HERE/) { # Do stuff } }