The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.


Twitter::TagGrep - Find messages with selected tags in Twitter timelines


Version 1.00


    use Twitter::TagGrep;
    use Net::Twitter;

    my $twit = Net::Twitter->new( ... );

    my $tg = Twitter::TagGrep->new( prefix => '#!',
                                    tags => [ 'foo', 'bar' ] );

    my $timeline = $twit->friends_timeline;

    # Get tweets containing one or more of #foo, #bar, !foo, or !bar
    my @matches = $tg->grep_tags($timeline);

    for my $tweet (@matches) {
      print $tweet->{text}, "\n", join(', ', @{$tweet->{tags}}), "\n";



Initializes and returns a new Twitter::TagGrep object.

Takes the following optional parameters:


A string defining the set of tag prefixes to recognize. Defaults to '#' (hashtags) if not specified.


Either a single tag to search for or a reference to an array containing any number of tags to search for.


If passed a parameter, replaces the set of recognized prefixes.

Returns the set of recognized prefixes as a single string value.


Appends all parameters to the set of recognized prefixes and returns that set.


If passed one or more parameters, sets the list of recognized tags. Any array references will add the contents of the referenced array, while other parameters will be used as-is.

Returns an array of recognized tags.


As tags, but appends to the list of tags rather than replacing it.


Takes a single scalar parameter referencing a Twitter timeline as returned by Net::Twitter's *_timeline functions.

Returns an array of tweets found within that timeline which contain at least one instance of (any character found in the prefix setting) followed by (any string listed in the tags setting). This check is case-insensitive.

A list of tags found in each returned tweet is added to it under the "tags" hash key.

The tag must normally stand alone as a word by itself, but can be matched as a substring by using regular expression metacharacters in tags values. Wildcard searches may also be done in this fashion, such as using the value "\w+" to locate all tweets containing one or more tags.


Dave Sherohman, <dave at>


Please report any bugs or feature requests to bug-twitter-taggrep at, or through the web interface at I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.


You can find documentation for this module with the perldoc command.

    perldoc Twitter::TagGrep

The latest version of this module may be obtained from


You can also look for information at:



Copyright 2009 Dave Sherohman, all rights reserved.

This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.