#!/usr/bin/env perl use 5.01800; use warnings; my @cases=( "<1>" ,"<1,2>" ,"<1,2,<3,4>,5,6>" ); my $re=qr{(?x) (?&LIST) (?(DEFINE) (? < (?&ITEM) (?: , (?&ITEM))*+ > ) (? \d*+ | (?&LIST) ) ) }; for my $case (@cases) { say qq{$case\n}, $case =~ qr{$re} ? "matches: '$&'" : "doesn't match"; }; __END__ #### perl Conway_01.pl <1> matches! <1> <1,2> matches! <1,2> <1,2,<3,4>,5,6> matches! <3,4> !!!! shouldn't this be <1,2,<3,4>,5,6>