use Regexp::AllMatches; my $matcher = Regexp::AllMatches->new(STRING => qr/PATTERN/); while (my ($match) = $matcher->next) { print "$match\n"; }