I hope that my question has not already been posed by someone else, since I tried to look almost everywhere in the site but I couldn\'t manage to find an answer.
My
You have to use looakahead
and count the number of matches
(?=beta|alpha)
Not tested in perl but should work
works here
The following uses a zero-width assertion (I believe that's what it's called).
#!/usr/bin/perl
use strict;
use warnings;
$_ = "betalphabetabeta";
while (/(?=(alpha|beta))/g) {
print $1, "\n";
Prints:
C:\Old_Data\perlp>perl t9.pl
beta
alpha
beta
beta