It might be worth pointing out the CPAN module Data::Munge which has a function list2re to make a list-matching regex. This line is basically what you need:
my $re = join '|', map quotemeta, sort {length $b <=> length $a || +$a cmp $b } @_;
There is also this, which is what I use.
In reply to Re^3: Combining multiple =~ s/
by no longer just digit
in thread Combining multiple =~ s/
by hennesse
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |