fork download
  1. #!/usr/bin/perl
  2. use 5.016;
  3. use warnings;
  4.  
  5. sub chunk {
  6. my $n = shift;
  7.  
  8. my @l;
  9. foreach(0 .. $#_){
  10. push @{$l[$_ / $n]}, $_[$_];
  11. }
  12.  
  13. return @l;
  14. }
  15.  
  16. sub len { length($_[0]) > 1 ? length($_[0]) : '' }
  17.  
  18. sub f { map{ $_->[1] . len($_->[0]) } chunk(2, shift =~ m/\G((.)\2*)/g) }
  19.  
  20. say f("aaaaaaaaaabbbbbbbbbbbbcccccccddddddddddeeeeeeefffffffffghiiiiiiiii");
  21.  
Success #stdin #stdout 0s 3692KB
stdin
Standard input is empty
stdout
a10b12c7d10e7f9ghi9