use strict; binmode STDIN; # put STDIN in binary mode while () { s/\033[^m]*m//g; # strip ansi color commands print $_; }