or download this
print join ":", $x=~/\G # start where prev match left off
(?:\A\[)? # if start of string, expect [
...
/gcx;
# if whole string was parsed, pos will be defined and equal to length
print "error" unless pos($x) && pos($x) == length($x);