def matching(p, S){ found = false (0..(S.size()-p.size())).each{ si -> nrMatched=0 (0..p.size()-1).each{ pi -> if(p[pi] == S[si+pi]) nrMatched++ } if(nrMatched == p.size()) found = true } return found } S="All Algorithms are cool." p="algo" println(matching(p, S))