use strict; use warnings; my $string = '0123efg789efg13'; my @matches; my $x='efg'; #the pattern for (0..10000) { if($string =~ /$x/g){ push @matches, $-[0]; push @matches, $+[0]-1; push @matches,"\n"; } else {last} } print "@matches\n";
In reply to using foreach with a regex by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |