It appears blazar has the best approach. I added data validation to, and bencmarked, the two main solutions (regexes and unpack), as well as doing the same thing with sprintf (just for fun).

@my_array = <DATA>; use Benchmark ':all'; sub regex_method { my $array = [@_]; for (@$array) { next unless /^\d{6}\s*$/; ## validate data s:(\d{2})(?!$):$1/:g; } } sub sprint_method { my $array = [@_]; for (@$array) { next unless /^\d{6}\s*$/; ## validate data $_ = sprintf "%d%d/%d%d/%d%d", split('',$_); } } sub unpack_method { my $array = [@_]; for (@$array) { next unless /^\d{6}\s*$/; ## validate data $_=join '/', unpack 'A2' x 3, $_ for @arr; } } cmpthese( 50000, { 'regex' => sub { regex_method(@my_array) }, 'sprintf' => sub { sprint_method(@my_array) }, 'unpack' => sub { unpack_method(@my_array) }, }); __DATA__ 010203 020304 012398 122399

With these results (representative of many runs):

Rate sprintf regex unpack sprintf 20383/s -- -23% -79% regex 26441/s 30% -- -73% unpack 96899/s 375% 266% --
<-radiant.matrix->
Larry Wall is Yoda: there is no try{} (ok, except in Perl6; way to ruin a joke, Larry! ;P)
The Code that can be seen is not the true Code
"In any sufficiently large group of people, most are idiots" - Kaa's Law

In reply to Re: modify the contents of an array by radiantmatrix
in thread modify the contents of an array by s_gaurav1091

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.