while ($w =~ /((.)(\2{7}|\2{3}|\2))/sg) { ... do something ... } #### #!/usr/bin/perl use strict; use warnings; my $t = pack "H*", '0a0a0a0a0b0b0a0a0c0c0c0c0c0c0c0c' . '1f1f2b2b2b2b3e3e7b7b7b7b7b7b7b7b' . '8f8f8f8f8f8f8f8f6c6c4b4b4b4b3f3f' . '9d9d0f0f0f0f0f0f0f0f3a3a2e2e2e2e'; repeats($t); repeats('abbcccddddeeeeeffffffggggggghhhhhhhhiiiiiiiii'); sub repeats { my $w = shift; print "\nBYTES: ", unpack("H*",$w),"\n"; while ($w =~ /((.)(\2{7}|\2{3}|\2))/sg) { my $bytes = $1; my $hex = unpack "H*", $bytes; $bytes =~ s/[\x00-\x1f\x80-\xff]/_/g; print "repeat: $hex ($bytes) pos:", pos($w)-length($bytes), "\n"; } }