SYNOPSIS use String::Elide::Parts qw(elide); Eliding string with no parts: my $text = "this is your brain"; # 0----5---10---15---20 elide($text, 16); # -> "this is your ..." elide($text, 16, {truncate=>"left"}); # -> "...is your brain" elide($text, 16, {truncate=>"middle"}); # -> "this is... brain" elide($text, 16, {truncate=>"ends"}); # -> "... is your b..." elide($text, 16, {marker=>"--"}); # -> "this is your b--" Eliding string with multiple parts marked with markup. We want to elide URL first (prio=3), then the Downloading text (prio=2), then the speed (prio=1, default): $text = "Downloading http://www.example.com/somefile 320.0k/5.5M"; # 0----5---10---15---20---25---30---35---40---45---50---55---60 elide($text, 56); # -> "Downloading http://www.example.com/somefile 320.0k/5.5M" elide($text, 55); # -> "Downloading http://www.example.com/somefile 320.0k/5.5M" elide($text, 50); # -> "Downloading http://www.e..com/somefile 320.0k/5.5M" elide($text, 45); # -> "Downloading http://ww..m/somefile 320.0k/5.5M" elide($text, 40); # -> "Downloading http://..omefile 320.0k/5.5M" elide($text, 35); # -> "Downloading http..efile 320.0k/5.5M" elide($text, 30); # -> "Downloading ht..le 320.0k/5.5M" elide($text, 25); # -> "Downloading . 320.0k/5.5M" elide($text, 24); # -> "Downloading 320.0k/5.5M" elide($text, 23); # -> "Download.. 320.0k/5.5M" elide($text, 20); # -> "Downl.. 320.0k/5.5M" elide($text, 15); # -> ".. 320.0k/5.5M" elide($text, 13); # -> " 320.0k/5.5M" elide($text, 10); # -> " 320.0k/.." elide($text, 5); # -> " 32.." # 0----5---10---15---20---25---30---35---40---45---50---55---60 DESCRIPTION String::Elide::Parts is similar to other string eliding modules, with one main difference: it accepts string marked with parts of different priorities. The goal is to retain more important information as much as possible when length is reduced. FUNCTIONS elide($str, $len[, \%opts]) => str Elide a string if length exceeds $len. String can be marked with ... so there can be multiple parts with different priorities and truncate direction. The default priority is 1. You can mark less important strings with higher priority to let it be elided first. The markup will be removed from the string before eliding. Known options: * marker => str (default: '..') * truncate => 'left'|'middle'|'middle'|'ends' (default: 'right') * default_prio => int (default: 1) SEE ALSO Similar elide modules Text::Elide is simple, does not have many options, and elides at word boundaries. String::Truncate has similar interface like String::Elide::Parts and has some options. String::Elide::Lines is based on this module but works on a line-basis.