perl -pe 's/(\w)(\w+)(\w)/split"",$2;$,="";$,.=splice@_,rand@_,1while@_;$1.$,.$3/eg' file