use strict; use warnings; use Test::More; my @good = ( '1234', '5566foo bar', 'baz9980' ); my @bad = ( 'a', '12', '12.4', '-124baz', '2018-01-01' ); my $re = qr/\d{4}(?!-)/a; plan tests => @good + @bad; for my $str (@good) { like ($str, $re, "$str matched"); } for my $str (@bad) { unlike ($str, $re, "$str not matched"); }