Your definition for @allColors should use " instead of ' in order for the escape sequences to be interpreted with meaning.
i.e.
my @allColors = "\e[48;5;1m \e[48;5;2m \e[48;5;3m \e[48;5;4m \e[48;5;5m".words;
The escape characters are encoded in a string when the string is first evaluated.
e.g.
my $notNewline = '\n';
my $newline = "\n";
print "Foo $newline Bar $notNewline"
will output Foo  Bar \n even though the $notNewline
is printed using "