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
pie ^ ^^ pi ^ ^^ ^^^^ ^ ^^^^^ ^^^^^ ^^^ ^^^^ ^^ ^ ^^^^^^^^^
{"pie"=>9, "pi"=>6}
The brand new service which powers Ideone!
Widget for compiling and running the source code in a web browser!