in reply to Re: Detecting whether forward slash is present in string
in thread Detecting whether forward slash is present in string

I agree that a solution where you start by just concatenating the strings, and then deal with duplicate // characters later is probably a fairly simple approach. Here's a solution similar to yours but using a negative lookbehind assertion to preserve the // if it follows a word character and a colon. That should prevent "http://" from becoming "http:/" (just as your solution also prevents this problem).

One issue with both of our solutions is that "file:///...." would be changed to "file://".

Here it is...

use strict; use warnings; while ( <DATA> ) { chomp; next unless $_; print "$_\t=>\n"; s{(?<!\w:)//}[/]g; print "$_\n\n"; } __DATA__ http://www.perlmonks.org/index.html http://www.perlmonks.org//index.html http:///davido.perlmonk.org/index.html http://www.yahoo.com:8080/index.html

Dave