# Note: Still has underscsores: my @collections = map { $_ =~ s/\.txt//; $_ } grep {/^\p{uppercase}/} @collections_list; # $collection guaranteed to match one of your file names. my $collection_raw = $cgi->param('collection'); my ($collection) = grep { $_ eq $collection_raw } @collections; $collection //= 'Deafult'; # If your file names might have <>", you can still do this: $collection = encode_entities($collection); # Without underscores my @collection_labels = map { $_ =~ s/_/ /g; $_ } @collections;