in reply to Counting to add space to a string

You could also use look-behind and look-ahead assertions to find the point in the string where the initial letters end insert the required number of 'X's using a regex substitution using the 'e' modifier.

knoppix@Microknoppix:~$ perl -E ' > @accts = qw{ > CAL2345-06 > CALI123456-09 > FLOR1234567-01 > MEGA9988776655-43 > }; > say for > map { > s{ (?<=[a-zA-Z]) (?![a-zA-Z]) }{ q{X} x ( 14 - length ) }xe; > $_; > } > @accts;' CALXXXX2345-06 CALIX123456-09 FLOR1234567-01 MEGA9988776655-43 knoppix@Microknoppix:~$

I hope this is helpful.

Cheers,

JohnGG

Replies are listed 'Best First'.
Re^2: Counting to add space to a string
by aaron_baugher (Curate) on Sep 22, 2011 at 20:42 UTC

    Or do a normal greedy match on the letters, and insert the X's after them in the same fashion:

    s{ ^([a-zA-Z]+) }{ $1 . 'X' x ( 14 - length ) }xe;