The spec is kind of vague about how to do error handling... and whether white space is significant... and how the accumulator should be accessed... and pretty much everything else too.
class HQ9Interpreter { has @!code; has $!accumulator; has $!pointer; method run ($code) { @!code = $code.comb; $!accumulator = 0; $!pointer = 0;while $!pointer < @!code {given @!code[$!pointer].lc {when'h' { say'Hello world!' }when'q' { say @!code }when'9' { bob(99) }when'+' { $!accumulator++ }default { note "Syntax error: Unknown command \"{@!code[$!pointer]}\"" } } $!pointer++; } }subbob ($beer is copy) {subwhat { "{$beer??$beer!!'No more'} bottle{$beer-1??'s'!!''} of beer" };subwhere { 'on the wall' };subdrink { $beer--; "Take one down, pass it around," }while $beer { .sayfor"&what() &where(),", "&what()!","&drink()", "&what() &where()!", '' } }}# Feed it a command string:my $hq9 = HQ9Interpreter.new;$hq9.run("hHq+++Qq");say'';$hq9.run("Jhq.k+hQ");