my $cache = []; sub print_columns { my $str = $_[0]; my $width = 0; for my $i ( 0 .. ( length( $str ) - 1 ) ) { my $c = ord substr $str, $i, 1; if ( ! defined $cache->[$c] ) { $cache->[$c] = char_width( $c ); } $width = $width + $cache->[$c]; } return $width; }