Use tr to squelch the spaces; and the return value plus a little math to pad to the required length:
$s = 'fred bill john';; $s .= ' 'x ( 37 - length( $s ) + $s =~ tr[ ][]s ); print "'$s'";; 'fred bill john '
In reply to Re: Remove whitespace in string and maintain overall length
by BrowserUk
in thread Remove whitespace in string and maintain overall length
by silentbob343
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |