Thanks for quick response. This works when i have only one bunch to summarize. However i have many such varied strings. My goal was: => if strings only vary in a "number" like p0/p1 m0/m1 b0/b1 c1_0/c1_1 e.t.c they should be summarized. => if they vary in any other character, then its a new string and it should be left alone (or) summarized with similar ones like for example, if i add one more string: a/b/c/p0/m0/d1/r_a_c1_0/q The o/p should be: a/b/c/p0/m0/b*/r_a_c1_*/q a/b/c/p0/m0/d1/r_a_c1_0/q