in reply to Trouble printing default variable in "foreach" loop.

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 } }

First off, you don't need to sort as you're going - sort it after you've grabbed the items you're interested in. A simpler version might be:

my @cityKeys = sort grep { /city/ } @cgiParamKeys; my @distanceKeys = sort grep { /distance/ } @cgiParamKeys;
That said, I doubt that sorting them is important at all. Next, your "@hiddenKeys". First off, you're creating a double-quoted (qq) string that is all the city and distance keys. That's not what you want. You want my @hiddenKeys = (@cityKeys, @distanceKeys); although you don't even need that. You can just loop through them later:
foreach (@cityKeys, @distanceKeys)
Inside this loop, you can combine the two conditionals to:
if (/city/ || /distance/)
But even then, your list of city and distance keys will always match, and you'll always want to output them, so you can just skip the conditional:
foreach (@cityKeys, @distanceKeys) { print $cgi->hidden($_ => $cgiParam{$_}); }
That said, you could continue to simplify the whole thing by creating a "city hash" that only contained city and distance keys, then you could dump this out even easier. But that's something I'll let you think about after absorbing this far. :-)

(PS: ++ for the progress - good job.)