use CGI; my $cgi = CGI->new({ foo=> '23 & 42', bar => 42}); my $url = $cgi->query_string;