If the patterns are all simple, one approach would be to represent each pattern as a list of atoms, and test whether a partial pattern can consume the buffer:
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";
}
}
This method will fail if you use alternation, or atoms with a minumum length > 1, such as "a{5}".