http://qs1969.pair.com?node_id=413494


in reply to Mysterious append failure.

Lexical $b is out of scope. see

D:\temp>perl -MO=Deparse -e "my $b = 1 for 1 .. 10" ; foreach $_ (1 .. 10) { my $b = 1; } -e syntax OK D:\temp>

So, your code is the same as

P:\test>perl -wl my $a = 'a' x 10; foreach $_ (0 .. 9) my $b .= substr( $a, $_, 10-$_ ) . '-' x $_; } print $main::b; ^Z Use of uninitialized value in print at - line 3.