http://www.perlmonks.org?node_id=512782


in reply to Elegant way to split into sequences of identical chars?

I know, obfuscated != elegant. Nevertheless, I thought it was kind of neat.
my $str = 'xx556xx'; my @x = grep --$|, $str =~ m/((.)\2*)/g; print join ',', @x;
The trick with $| is that it's a toggle, so grep throws away every other member of its input. The same thing could be done with a normal variable like so:
my $str = 'xx556xx'; my $tog = 0; my @x = grep $tog = !$tog, $str =~ m/((.)\2*)/g; print join ',', @x;
or using split:
my $str = 'xx556xx'; my $tog = 0; my @x = grep $tog = !$tog, split /(?<=(.))(?!\1)/, $str; print join ',', @x;

Caution: Contents may have been coded under pressure.