Matching two overlapping patterns with Perl
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 problem is: I'm making a PERL script which has to detect the position of every occurrence of one or another pattern in a string. For instance: $string = "betaalphabetabeta"; $pattern = "beta|alpha"; In this case, I would like my script to return 4 matches. I thought that this could be easily achieved by using the match operator in someway like this: $string =~ /beta|alpha/g; However, since my two patterns ("alpha", "beta") are