I would go the other way around and define the colors as global variables and set these to be empty in the case where no colors are wanted:
my $red = "\033[31m"; # is there a semicolon missing at the end of the + ANSI escape? if( $ENV{NO_COLOR} || ! -t) { $red = ""; }
See also https://no-color.org and Term::ANSIColor::Conditional.
In reply to Re: Can't remove ANSI markup
by Corion
in thread Can't remove ANSI markup
by glendeni
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |