in reply to How to write better code?

You want to use the CGI.pm module, which can parse that:

use strict; use CGI; my $string = "name=alex&sex=m&age=20"; my $q=CGI->new($string); print Dumper scalar $q->Vars()"

If you actually are, as it looks, parsing a CGI query, the CGI module can also take all of the other chores of parsing CGI queries for you:

use strict; use CGI; my $q=CGI->new(); # parses all CGI parameters print $q->header('text/plain'); print Dumper scalar $q->Vars()"