use Modern::Perl; use URI::Escape qw/uri_escape/; my @t = qw(name John number 7 status unknown); $t[1] = 'John Smith'; # something that needs escaping my $str = ''; while (@t) { $str .= sprintf( '%s=%s', uri_escape(shift @t), uri_escape(shift @t), ); $str .= '&' if @t; } say $str;