1) You can simply include ANSI codes in the heredoc:
print <<EOD; XXXX\033[1;30;40m YYYY\033[1;33;43m ZZZZ\033[0mRESET EOD
2) Heredoc interpolates variables, so if you include ANSI colors in a variable, it works.
my $v="xxxxx"; $var = "\nXXXX\033[1;30;40m YYYY\033[1;33;43mZZZZ\033[0mRESET\n"; print <<EOD; $var EOD
3) Based on # 2, you can generate ANSI codes using the Term :: ANSIColor color() method as a string and use the variable containing this string in the heredoc . Sorry, there is no working example, since I do not have ANSIColor installed, but it should be obvious.
You may want to store the specific ANSI code in some specific variable and put the actual text in the heredoc and sprincle ANSI code variables there.
source share