#!/usr/bin/perl -wT print "
\n"; nest(0, 5, 5, 'span'); print "
\n"; :nth-child(-1n+6) :nth-child(-2) :nth-child(-2n-2) sub nest { my($indent, $remaining, $count, $element, @position) = @_; ++$indent; --$remaining; for (my $index = 0; $index < $count; ++$index) { if ($remaining > 1) { print((' ' x $indent) . "<$element>\n"); nest($indent, $remaining, $count, $element, @position, $index); print((' ' x $indent) . "\n"); } elsif ($remaining) { print((' ' x $indent) . "<$element> "); nest($indent, $remaining, $count, $element, @position, $index); print "\n"; } else { my $class = tryToMatch(\@position, [nthChild(-1, 6), nthChild(0, -2), nthChild(-2, -2)]) ? 'match' : 'nomatch'; print "<$element class="$class">Test "; } } } sub nthChild { my($position, $counts) = @_; if }