$c = "test test test"; $c = correct_length($c); $fmt = "A4 x1 A4 x1 A4 x1 A4"; @c = unpack($fmt, "$c"); print join ("*",@c), "\n"; $d = "test test test "; $d = correct_length($d); $fmt = "A4 x1 A4 x1 A4 x1 A4"; @d = unpack($fmt, "$d"); print join ("*",@d), "\n"; sub correct_length { my ($string) = shift; $string .= ' ' unless length($string) >= 15; return($string); } #### my %formats = ( "item_name" => 15, # where 15 is the length "item_name2" => 20, # etc. ); # code removed for demonstration $c = correct_length($c,'item_name'); sub correct_length { my ($string,$item) = @_; $string .= ' ' unless length($string) >= $formats{$item}; return($string); }