my @cityKeys; my @distanceKeys; foreach( @cgiParamKeys ) { if( /city/ ) { #If a hidden city field found store it in an array; push @cityKeys, $_; #Store the field in an array @cityKeys = sort @cityKeys; #Sort the array } if( /distance/ ) { #If a hidden distance field found, store it in an array push @distanceKeys, $_; #Store it in the array @distanceKeys = sort @distanceKeys; #Sort the array } } #### my @cityKeys = sort grep { /city/ } @cgiParamKeys; my @distanceKeys = sort grep { /distance/ } @cgiParamKeys; #### foreach (@cityKeys, @distanceKeys) #### if (/city/ || /distance/) #### foreach (@cityKeys, @distanceKeys) { print $cgi->hidden($_ => $cgiParam{$_}); }