#!/your/perl/here use warnings; use strict; while () { chomp; my $sort = join '', sort split ''; ( ( $sort =~ /^[afhmstw]+$/ ) # only these chars and ( $sort !~ /([afhmstw])\1/ ) ) # no repeats ? print "<$_> OK\n" : print "<$_> Not OK\n"; } __DATA__ smsa smta stmwhas BADsmtaEXAMPLE __END__ Not OK OK Not OK <> Not OK Not OK