in reply to Looking for less code

Before worrying about the amount of code, I'd first focus on making your code more idiomatic and self-documenting. Sometimes it takes more code, not less, to write good code. In addition to the indenting problem noted above, consider the following changes:

# your code looks like an extract from a larger document # but just in case you aren't # do use strictures and declare your variables # it will save you *A LOT* of debugging time use strict; use warnings; # DECLARE YOUR VARIABLES! my $FH = \*STDOUT; my $target_db = $ARGV[0]; my $target_os = $ARGV[1]; my $flag; while (my $line = <DATA>) { if ($line =~ /WNT/ || $line =~ /UNX/) { print "$line\n"; } # be consistant: # if you are unsetting a flag with undef, then always use # defined to check for an unset flag. Not everything that # is false is also undef. if (defined($flag)) { # Fix some potential bugs/cause for warnings: # * check to see if variables are defined before using # equals or regex comparisons. Otherwise you will get # warnings. # Make code more readable and self documenting # * negations are harder to read than positives # * conditions shouldn't be buried inside an else {...} if # they apply to the entire content of the block. # * or'd regexes can be combined into one to make it clearer # that one is interested in a set of alternatives if (defined($target_db)) { if ($target_db eq 'sql') { next if ($line =~ /informix|oracle/i); } elsif ($line =~ /$target_db/i) { next; } } #* conditions that apply to the entire block should be # part of the if/elsif clause UNLESS you expect to be # expanding a simple condition to a full fledged if-else print $FH "$line"; if (defined($target_os)) { # leaving room for a more complicated target_os logic # later on if ($line =~ /$target_os/) { undef $flag; next; } } } #* defined is a fast check, so do it first #* defined($flag) is better than (defined $flag) #* double quoting a single variable is redundant. #* if we're not expecting more complicated logic # combine all conditions that apply to the block into # the if statement if (!defined($flag) && ($line =~ /UNX|WNT|COMPONENT/)) { $flag = 1; print $FH $line; } }

Best, beth