use strict; use warnings; use Data::Dumper; print join " ", splitSameChars('xx556xx'); sub splitSameChars { my $letters = shift; push @_, $1 while $letters =~ /((.)\2*)/g; @_; }