Evaluated set brr {b e r r y}; set fag [regsub -all {(f|a|g)} [berry] [invert " "]]; set out ""; for {set i 0} {$i < [string length $fag]} {incr i} { if {[string index $fag $i] eq ":"} {append out [lindex $brr 1]} else {append out [string index $fag $i]}};. $out