use strict; use warnings; use Test::More; $\="\n"; # search for 'ax', not followed by 'ba' my @teststr = ('0axba', # simple not ok '1axbb', # one char ok, one not '2axccaxdd', # simple 2 times '1axbaxcc', # one time (sequence combined) '1axcaxcc' # one time (sequence combined) ); my @reg = ( qr/ax(?!ba)/, # look ahead qr/ax[^b][^a]/, # 2 not char sets ); plan tests => @teststr*@reg; for my $re (@reg) { print "---------------\n$re\n---------------"; for my $str (@teststr) { my $str1=$str; my $str2=$str; # get teststring $str1=~s/^\d//; # remove result my $got = $str1=~s/$re/-/g; # replace (do test) $str2=~s/^(\d)//; # remove result and remember cmp_ok($got, '==', $1, "($1) $str2 => $str1 "); #check } }