my $negated = qr{^(?!.*?$regex)}s; #### #!/usr/bin/perl use warnings; use strict; use Test::More qw(no_plan); # first item: regex # second item: list of strings that regex should match # third item: list of strings that negated regex should match my @r = ( [qr{a}, ['a'], ['', 'b']], [qr{^a}, [qw(a ab)], ['', 'b', 'ba']], [qr{a$}, [qw(a ba aba)], ['', 'b', 'ab']], ); for (@r){ my ($re, $pass, $fail) = @$_; my $negated = qr{^(?!.*?$re)}; for (@$pass){ like $_, $re; unlike $_, $negated; } for (@$fail){ like $_, $negated; unlike $_, $re; } }