use URI::Escape; my $s = 'http://foo/bar/'; print uri_escape($s);