sub select_your_school { my $namesref = shift; # create a list of sorted hash keys my @menuitems = sort keys %$namesref; print $q->header, $q->start_html(-title=> 'Select Your School'), "Please select your school from the following list:", $q->start_form, $q->popup_menu( {-name => 'school_id', -values => \@menuitems , }), ....