http://qs321.pair.com?node_id=927466

blakew has asked for the wisdom of the Perl Monks concerning the following question:

Bit of silliness.

1. What's the next line?

1 1 1 2 1 1 2 1 1 1 1 1 2 2 1

2. Write code to print each line in the pattern (it gets unwieldy).

If the 5th line was 3 1 1 2 passing an argument gives that solution-
my $anchor = @ARGV ? '' : '^'; printf "%d\n", $_ = '1'; do { my $new; my ( $n ) = /^(\d)/o; while ( $_ ) { my $c = 0; $c++ while s/$anchor\s?$n\s?//; $new .= "$c $n " if $c; ( $n ) = /^(\d)/o; } print $_ = $new; } until ( <STDIN> =~ /\S/ );