I agree with what OeufMayo said about using CGI.pm,
and recommend you use buckaducks excellent code-snippet.
This code is maybe closer to what you had in mind:
$query = new CGI;
$value = $query->param("name$i");
last if ! $value;
# do something with value
but BEWARE: this has several problems.
for example: empty strings are treated as
no value at all and break the loop!
Brigitte 'I never met a chocolate I didnt like' Jellinek