m={}v={}i=0$<.map{|l|(t=l.chop![/\^+/])?v[m[i]=o=m[i-t.size]]+=1:v[m[i]=l]=1;i+=1}p v
I like dogs I like cats ^ ^^^ ^^ I like turtles ^ ^^^ ^^
{"I like dogs"=>2, "I like cats"=>4, "I like turtles"=>3}
The brand new service which powers Ideone!
Widget for compiling and running the source code in a web browser!