use strict; use warnings; use Test::More; my @good = ( 'a', '321', '(321)', 'a(321-)_HGF' ); my @bad = ( '"@$', '~', '[{' ); my $re = qr/^[a-zA-Z0-9_()-]+$/; plan tests => @good + @bad; for my $str (@good) { like ($str, $re, "$str matched"); } for my $str (@bad) { unlike ($str, $re, "$str not matched"); }