It doesn't involve a regex, which would seem inappropriate for this problem, but either of the following two approaches should work:
>perl -wMstrict -le "my @raw_files = qw{ 12.png 06.png 06.png 03.png 07.png 07.png }; my $blank_png = 'blank.png'; my @blanked_files = interleave_blanks($blank_png, @raw_files); print qq{@blanked_files}; sub interleave_blanks { my $blank_file = shift; my $prev_file = ''; map { my $repeat = $_ eq $prev_file; $prev_file = $_; $repeat ? ($blank_file, $_) : ($_); } @_ ; } " 12.png 06.png blank.png 06.png 03.png 07.png blank.png 07.png >perl -wMstrict -le "my @raw_files = qw{ 12.png 06.png 06.png 03.png 07.png 07.png }; my $blank_png = 'blank.png'; my @blanked_files = do { my $prev_file = ''; map { my $repeat = $_ eq $prev_file; $prev_file = $_; $repeat ? ($blank_png, $_) : ($_); } @raw_files ; }; print qq{@blanked_files}; " 12.png 06.png blank.png 06.png 03.png 07.png blank.png 07.png
Update:

In case the animation sequence is a continuous loop and thus requires a blank .png inserted after the last .png in the array if the last .png is the same as the first .png, this should do the trick (although it might be a little more elegant without a bunch of reverses scattered all over the place):

>perl -wMstrict -le "my $blank_png = 'blank.png'; print qq{\noutput:}; for (@ARGV) { print qq{ in: $_}; my @raw_files = split; my @blanked_files = interleave_blanks($blank_png, @raw_files); print qq{out: @blanked_files}; } sub interleave_blanks { my $blank_file = shift; my $prev_file = $_[0]; reverse map { my $repeat = $_ eq $prev_file; $prev_file = $_; $repeat ? ($blank_file, $_) : ($_); } reverse @_ ; } " "12.png 06.png 06.png 03.png 07.png 07.png" "07.png 12.png 06.png 06.png 03.png 07.png 07.png" output: in: 12.png 06.png 06.png 03.png 07.png 07.png out: 12.png 06.png blank.png 06.png 03.png 07.png blank.png 07.png in: 07.png 12.png 06.png 06.png 03.png 07.png 07.png out: 07.png 12.png 06.png blank.png 06.png 03.png 07.png blank.png 07. +png blank.png

In reply to Re: Help with Image Magic by AnomalousMonk
in thread Help with Image Magic by gringocharlie

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.