I was using libpcre with C, where I could define callouts. They helped me to easily match not just words, but any subexpressions in any order. The regexp looks like:
(?C0)(expr1(?C1)|expr2(?C2)|...|exprn(?Cn)){n}
and the callout function guards that every subexpression is matched exactly once,like:
int mycallout(pcre_callout_block *b){
static int subexpr[255];
if(b->callout_number == 0){
//callout (?C0) - clear all counts to 0
memset(&subexpr,'\0',sizeof(subexpr));
return 0;
}else{
//if returns >0, match fails
return subexpr[b->callout_number-1]++;
}
}
Something like that should be possible in perl as well.