Sample code for 30+ languages & platforms
Perl

URL Encoding and Decoding

See more Encryption Examples

Demonstrates URL encoding and decoding.

Chilkat Perl Downloads

Chilkat2 Perl
use strict;
use warnings;
use Chilkat2;

# To URL encoding a string:
my $s = 'Why a > b?';

my $sb = Chilkat2::StringBuilder->new;
my $success = $sb->Append($s);

# URL encode the string.
$sb->Encode('url', 'utf-8');

# Show the URL encoded string:
my $sEncoded = $sb->GetAsString();
print $sEncoded, "\n";

# The result is:  Why%20a%20%3E%20b%3F

# If you prefer "+" instead of "%20" for SPACE chars:
my $numReplaced = $sb->Replace('%20', '+');
print $sb->GetAsString(), "\n";

# Output is:   Why+a+%3E+b%3F

# To decode:
$sb->Decode('url', 'utf-8');
print $sb->GetAsString(), "\n";

# Result is: Why a > b?