Most of the recent work in the domain of Programming by Demonstration do not tackle the problem of acquisition of complex program structures like loops. We propose a new algorithm to automate repetitive tasks and to memorize them as Prolog programs. An example of a task is a Prolog goals list. Our method searches for traces of recursive predicates definitions in examples. The Minimum Description Length Principle is the criterion that guide the choice of the algorithm. The construction of a Prolog program automating a task is based on the chosen traces and on constraints due to Prolog syntax and Prolog resolution. Our experimentations with PPD are encouraging.