fork download
  1. #!/usr/bin/perl
  2. use strict; use warnings;
  3. use Data::Dumper;
  4.  
  5. my $text = 'XYYYZ';
  6. my @source;
  7. push @{$source[$1 ? 0 : $2 ? 1 : 2]}, $& while $text =~ /(X)|(Y)|(Z)/g;
  8. print Dumper \@source;
Success #stdin #stdout 0.02s 7248KB
stdin
Standard input is empty
stdout
$VAR1 = [
          [
            'X'
          ],
          [
            'Y',
            'Y',
            'Y'
          ],
          [
            'Z'
          ]
        ];