my @lines; { local $_; while ( <$in> ) { # Remove leading and trailing whitespace s/^\s+//; s/\s+$//; # Remove comments from the first # to the end of the line s/#.*//; push @lines, $_ if length $_; } }