perl -lne "%ln;BEGIN{open $f,shift;map{chomp;$ln{$_}++}<$f>}print qq($ARGV line\t$.\t[$_]) if exists $ln{$_};close ARGV if eof" dog.txt cat.txt other.txt