$ cat A; echo '* * * * *'; cat B
apple
cherry
carrot
lime
* * * * *
lime
orange
banana
####
$ perl -e 'open F,$ARGV[0] or die;shift;my %set = map {$_ => 1 } <>; for () {print if $set{$_}};' A B
lime
##
##
$ perl -e 'open F,$ARGV[0] or die;shift;my %set = map {$_ => 1 } <>; for () {print unless $set{$_}};' A B
apple
cherry
carrot
##
##
$ cat C
grape
apricot
cherry
$ perl -e 'open F,$ARGV[0] or die;shift;my %set = map {$_ => 1 } <>; for () {print unless $set{$_}};' A B C
apple
carrot
$ perl -e 'open F,$ARGV[0] or die;shift;my %set = map {$_ => 1 } <>; for () {print if $set{$_}};' A B C
cherry
lime