in reply to Padding with \s

Well you can use sprintf, but I don't see why there's any need for a while loop.

$str = sprintf '%-40s', $str;
--
<http://www.dave.org.uk>

"The first rule of Perl club is you do not talk about Perl club."
-- Chip Salzenberg