package MyPackage; use strict; use Exporter qw( import ); our @EXPORT_OK = qw( print_columns ); sub char_width { ... } my $cache = []; sub print_columns { my ( $str ) = @_; 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; } 1;