my %compare; my %files = ( a => 'oldfile', b => 'newfile' ); # compare oldfile to newfile for my $filekey (keys %files) { open F, $files{$filekey} or next; while () { next if /^(#.*)\s*$/; # ignore blanks and comments $compare{lc $_} .= $filekey; } } print "Lines in newfile but not oldfile:\n", sort grep $compare{$_} !~ /a/, keys %compare; print "Lines in oldfile but not newfile:\n", sort grep $compare{$_} !~ /b/, keys %compare;