sub create_chunks {
     ($one, $two) = @_;
     @chunks = ();

     $one =~ /([^1]+)
             (?{         # beginning of code block
                 if ( ($i = index $two, $1) != -1) {
                     push @chunks, $1;
                     $len = length $1;
                     substr($one, $-[1], $len, '1'x$len);
                     substr($two, $i, $len, '2'x$len);
                 }
             })          # end of code block
             (?=9)       # match never
             /x;
     return sort @chunks;
}


sub min_chunks {
     my ($first, $second) = @_;

     my @c1 = create_chunks(lc $first, lc $second);
     my @c2 = create_chunks(lc $second, lc $first);

     return @c1 if @c1 < @c2;
     return @c2;
}

print min_chunks("trout", "tutor"), "\n";
print join "-", min_chunks("abcdefeg", "abcdegef"), "\n";
