# perldoc > URI::Escape

---
type: CommandReference
command: URI::Escape
mode: perldoc
section: 
source: perldoc
---

## Quick Reference

- `uri_escape($string)` — percent-encode unsafe characters
- `uri_escape($string, $unsafe)` — encode with custom unsafe set
- `uri_escape_utf8($string)` — encode as UTF-8 then percent-escape
- `uri_unescape($string)` — decode percent-encoded string
- `uri_unescape(@strings)` — decode multiple strings

## Name

Percent-encode and percent-decode unsafe characters as per RFC 3986.

## Synopsis

perl
use URI::Escape;
$safe = uri_escape("10% is enough\n");
$verysafe = uri_escape("foo", "\0-\377");
$str  = uri_unescape($safe);
## Functions

- `uri_escape($string, [$unsafe])` — Replaces each unsafe character in `$string` with the corresponding `%XX` escape sequence. Croaks if a character code > 255. Default unsafe set is `^A-Za-z0-9\-\._~`. The optional `$unsafe` is a regex character class string (e.g. `"\x00-\x1f\x7f-\xff"`).
- `uri_escape_utf8($string)` — Same as `uri_escape()` but encodes `$string` as UTF-8 first. Equivalent to `utf8::encode($string); uri_escape($string)`. Handles characters > 255. For chars 0-127, identical to `uri_escape()`.
- `uri_unescape($string)` — Replaces each `%XX` sequence with the corresponding byte (octet). Equivalent to `$string =~ s/%([0-9A-Fa-f]{2})/chr(hex($1))/eg`. If called with multiple strings, each is returned unescaped. Performance: ~40% slower if few escapes, ~700% slower if none, compared to inline RE.
- `%escapes` — Hash mapping all 256 bytes to their escape codes (e.g. `chr(0x20)` => `"%20"`). Faster than `sprintf("%%%02X", ord(...))`.

## Examples

perl
use URI::Escape;

# Basic encoding
my $safe = uri_escape("10% is enough\n");   # "10%25%20is%20enough%0A"

# Custom escape set (control and high-bit)
my $verysafe = uri_escape("foo", "\0-\x1f\x7f-\xff");

# Decoding
my $str = uri_unescape("10%25%20is%20enough%0A");  # "10% is enough\n"

# UTF-8 encoding
my $utf8_encoded = uri_escape_utf8("café");  # "caf%C3%A9"
## See Also

- [URI](https://perldoc.perl.org/URI) — Perl module for URI manipulation
- RFC 3986 — Uniform Resource Identifier (URI): Generic Syntax