my $re= qr/[^-_.~A-Za-z0-9!*'();:@&=+\$,\/?#\[\]]/; use bytes; $linkref =~ s/($linkref)/sprintf("%%%02X",ord($1))/ge;