One easy way:
$text =~ s!\b(http://)([^/]+)!$1 . " " x length($2)!e;
The regular expression \b(http://)([^/]+) matches the word boundary, the literal string http:// and one or more characters without a slash, capturing http:// at $1 and characters without a slash at $2 . (Note that I used ! As the regex separator above instead of the usual / to avoid the divergent toothpick syndrome .)
The switch e at the end of the s/// operator causes the substitution of $1 . " " x length($2) be replaced $1 . " " x length($2) $1 . " " x length($2) as Perl code instead of interpreting a string. Thus, it is valued at $1 , followed by as many spaces as there are letters in $2 .
source share