#!/usr/bin/perl -w use strict; my $str = "\033[32m coloured! \033[m"; my $visible_length = length( $str ); while ( $str =~ /\033\[\d*m/g ) { $visible_length -= length($&); } print "Visible Length = $visible_length (should be 11)\n";