use Term::ANSIColor ':constants'; # Note that there is not normally a space betweeh the . I added that so that Perlmonks.org wouldn't parse the post incorrectly. $_ = "normal green normal normal"; $GREEN = GREEN; $YELLOW = YELLOW; $RED = RED; $RESET = RESET; s((.+?))($GREEN$1$RESET)g; s((?<=\x1b)\[(.+?)\])($RED$1$RESET)g; s(())($YELLOW$1$RESET)g;