You are *so* the monk!
The regex works because if the variable ength of the space (0-full line) before matching the backreference. And lookaheads can be variable length.
This is essentially the converse approach to what I was thinking trying to solve the problem. Someday...
while (<DATA>) {
chomp;
if ( /^(?:([smtwhfa])(?!.*\1))*$/ ) {
print "$_ : OK\n";
} else {
print "$_ : Not OK\n";
}
}
__DATA__
swma
smqa
smsa
fhtm
ttma
t2ms
__END__
swma : OK
smqa : Not OK
smsa : Not OK
fhtm : OK
ttma : Not OK
t2ms : Not OK