use strict; # more lines could be added to this list my @lines = ("set CMP_DATA_INBND_DIR=C:\\h\\csscs\\data\\commi\\tmp_queue", "set CMP_DATA_OUTBND_DIR=C:\\h\\CMP\\data\\outbound", "set JAVA_HOME=C:\\h\\COTS\\JAVA2\\1.3", "set CSSCS_DATA=C:\\h\\csscs\\data"); # construct a hash of initial line count # e.g. # ( # lineA => 0, # lineB => 0 # ... # ) my %lines = map { $_ => 0 } @lines; my $file = shift or die "Input file argument missing!\n"; my $outfile = shift; # determine default output file name if not specified by the user. $outfile ||= "$file.out"; open (IN, "<$file") or die "Failed to open file $file!\n"; open (OUT, ">$outfile") or die "Failed to open file $outfile!\n"; while () { chomp; # increment line count if present in the file $lines{$_}++ if exists $lines{$_}; # for now just print back to the output file print OUT "$_\n"; } for (keys %lines) { # print lines that were missed from the input file # (count 0) print OUT $_ . "\n" unless $lines{$_}; } close(IN); close(OUT);