It's a bug in Rakudo that it doesn't reject the program at compile time, because $var isn't declared (yet). It's one of our oldest open bugs.

Update: It should be noted though that lexical variables are always scoped to a block in Perl 6, and that the detection of of undeclared variables happens only at compile time. Thus this piece of code works differently in Perl 5 and Perl 6 (and this time Rakudo is correct here):