$ perl -Mstrict -wE 'my $str = q{[\033[96m]word[\033[0m]}; say $str; say $str =~ s/ \[ \\? \d+ [a-zA-Z]? \]? //gxr' [\033[96m]word[\033[0m] word