Looking on google I found this:
replace( T1, S1, S2, T2 ) :-
segment( T1, Pre, S1, Post ),
append( S2, Post, S2_plus_Post ),
append( Pre, S2_plus_Post, T2 ).
segment( T, Pre, S, Post ) :-
segment_1( S, T, Pre, Post ).
segment_1( [], L, [], L ) :- !.
segment_1( [H|T_]...