in reply to Symbols in regex

sort {length $columnA <=> length $columnB} keys %dic; where do $columnA and $columnB come from? If you print $regex; do you get the expected result (an actually sorted list of alternatives?).

If you don't give us a fully working exemple we can only guess blindly. See How do I post a question effectively?

And to give us your input data, you can do something like:

use Data::Dumper; # Code to fill %dic print Dumper \%dic;