#!/usr/bin/perl use warnings; use strict; use feature qw{ say }; my $bob = 'bob'; sub match { my ($string, $regex) = @_; say $string, "\t", $regex; my @chars = split //, $regex; for my $pos (1 .. $#chars) { my $re_part = join q(), @chars[0 .. $pos]; return 1 if eval { $string =~ /^($re_part)$/ and length $1 }; } return 0 } for my $regex ( 'bobly', 'bo*[a-z].', 'bob', 'bo(x)?bcd', 'fred', 'o*', ) { say match('bob', $regex); }