use URI::Split qw(uri_split); my $uri = 'http://example.net/?foo=bar&baz=fu'; my ($scheme, $auth, $path, $query, $frag) = uri_split($uri); my @sorted_query = sort split /&/, $query; $query = join '&', @sorted_query; my $new_uri_string = $scheme . $auth . $path . $query . $frag;