my $x = "abcccabcccabbbb"; while ($x =~ /([ab])/g) { print "Found '$1'\n"; }