for ($obj->method =~ /pat(keep)/g) { print $count++, " $_\n"; # etc. }