I am just wondering if there is better(clean) way to do this,
use strict; use warnings; my $val1 = '5234'; $val1 = append($val1,'_'); unless($val1) { print "return undef\n"; } print "$val1\n"; sub append { my $val2 = shift; my $character = shift; if($val2 =~ /\d\d\d\d/) { $val2 =~ s/(\d)(\d)(\d\d)/$1$character$2$character$3$4/g; } elsif($val2 =~ /\d\d\d/) { $val2 =~ s/(\d)(\d)(\d)/$1$character$2$character$3/g; } elsif($val2 =~ /\d\d/) { $val2 =~ s/(\d)(\d)/$1$character$2/g; } else { return; } return $val2; } Cheers! <br> Marshall, <br> First of all thank for reply But if there is 4 digit(5234) I want it t +o be(5_2_34)!<br> where as for 3(523) I want it (5_2_3)<br> and for 2(52) is want it to be (5_2)<br><br> Thanks any way!!!<br>

In reply to Check substitute digit by tart

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.