Here's an (almost) one-line solution.

It took a few minutes, but this looks like a good prototype for your needs. You will likely need to adjust the tests on the position variable $i to fit your need more precisely...

use strict; my $str = 'a,b,c,d,e,f,g,h,i,j,k,l,m,n'; print "$str\n"; my $i = 0; $str =~ s/(.)/$i++;($1 ne ',' or $i>15 && $i<25) ? $1 : '#'/ge; print "$str\n";
This prints:
a,b,c,d,e,f,g,h,i,j,k,l,m,n a#b#c#d#e#f#g#h,i,j,k,l,m#n
I used '#' instead of "\t" for demo purposes so things would line up nicely in the print test.

Note: along the way I tried using pos instead of $i, but apparently it is undefined while still in the right side of the s///. Update: Hofmator is correct to say I am wrong to imply that pos would work outside the s///.   pos is not set at all for s///.

Note 2: I offer this as a solution to the problem as you described it but it seems very odd that you would have a list of companies with names that are exactly 10 characters long.


In reply to Re: Help with substitution - - 15 Characters from the left by dvergin
in thread Help with substitution - - 15 Characters from the left by La12

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.