use strict; use warnings; my @words = qw{ test tesi stoat trout }; my $regex = qr {(?x) ^ (.) .*? (?!\1) . $ }; print m{$regex} ? qq{ Matched: $_\n} : qq{Not matched: $_\n} for @words; #### Not matched: test Matched: tesi Matched: stoat Not matched: trout