while () { chomp; s/#.*$/ /; # first replace any comments with space # skip this line if it consists only of whitespace (or nothing) next if /^\s*$/; # at this point we KNOW there is at least some non-blank on the line # which is also non-comment. # Just grab everything sans leading/trailing whitespace my ($non_blank) = /^\s*(.+)\s*$/; push @enabled_lines, $non_blank if $non_blank; # 'if' may not be necessary }