Akin to Google's former Code Search, this aims to search all the code found on CPAN. It concentrates on searching code; if you just want to look for a module use MetaCPAN instead.

Regular Expressions are supported via re::engine::RE2 (which wraps Google's RE2 engine). This means that the regexps supported are mostly Perl compatible but are not totally compatible with Perl. Of particular note is look-ahead and look-behind are not supported, for more details see RE2's supported syntax.

(Due to performance concerns re::engine::RE2's ability to fallback to Perl regexps is disabled.)


The following operators are supported, they accept regexps (after the colon) and can be negated with a - prepended to their name. Anything that does not match this syntax will be treated as a regexp on the code itself.

A useful shortcut for these operators is to use '=' rather than ':' as a separator, this does a full string match (i.e. wraps anchors around the supplied regexp so file:^Makefile\.PL$ is the same as file=Makefile\.PL).

For example -dist=perl to exclude perl, file:.xs to search only XS files or -file:"ppport\.h" to exclude ppport.h.

Much of the power of this tool comes from the fact that raw regexps can be used. By default the search is case sensitive, but (?i) or (?i:regexp) syntax can be used to make it case insensitive. Escapes such as \n can be used to match on newlines or the (?s) modifier (be careful with this, very greedy matching is limited for resource reasons, you may find writing a regexp such as .{1,10} rather than blindly writing .* is more effective).


A picture is worth a thousand words:

(If you find any more good examples please send them my way.)


There is an experimental API (i.e. subject to change), using the same syntax as the normal searches at: For example: If you expect to make heavy usage of this please ensure you send a User-Agent header that describes your application (ideally with contact details) and send a mail to the mailing list so we can keep track of users.

Command line client

There is a command line client on CPAN: App::cpangrep.

This is particularly useful for scripting, e.g. to find the intersection of distributions where the file dist.ini contains "[Prereq" and "@Author:ETHER" you can use: comm -12 <(cpangrep -l file=dist.ini \\\[Prereq | sort) <(cpangrep -l file=dist.ini @Author::ETHER | sort)


Written by David Leadbeater. For help use the cpangrep mailing list or ask me (dg) on, #toolchain.

Contributions are welcome; you can find the git repository at github (including the issue tracker).

Thanks to taras for help with graphics and layout.
Home · About