use strict; use warnings; use Test::More; my @good = ( 'aa1.2', 'aa1_bb2' ); my @bad = ( 'aa1_2', 'aa1_2bb', '1aa' ); my $re = qr/^[a-z][^_]*(_[a-z].*)?$/; plan tests => @good + @bad; for my $str (@good) { like ($str, $re, "$str matched"); } for my $str (@bad) { unlike ($str, $re, "$str not matched"); }