my @re= qw( [abc] b+ c ); my @tests = qw( a ab ba bb bbbbbcdef bbbbbbg ); TEST: foreach my $buff ( @tests ) { my @tre = @re; my $tre = ""; while (@tre > 1) { $tre .= shift @tre; if ( $buff =~ m/^$tre$/ ) { print "Test string '$buff' matched partial pattern, $tre\n"; next TEST; } } $tre .= shift @tre; if ( $buff =~ m/^$tre/ ) { print "Test string '$buff' matched whole pattern, $tre\n"; } else { print "Test string '$buff' did not match pattern $tre\n"; } }