$ perl -wl $str = 'abc'; $str =~ s/^(.+)$/sprintf("%s%s", $1, 'X'x(10-length($1)))/e; print $str; abcXXXXXXX