This seems to work, using a negative look-ahead.
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;
Prints
Not matched: test Matched: tesi Matched: stoat Not matched: trout
I hope this is helpful.
Cheers,
JohnGG
In reply to Re: How to use a negative backreference in regex?
by johngg
in thread How to use a negative backreference in regex?
by larryk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |