$str =~ s#/## for 1,2; #### s#(/\s*){2}\z## #### perl -i.old -pe '$sawSlash++ && s#/## if m#/#'