Short Example

#!/usr/bin/perl -w
use strict;
use Parse::RecDescent;
$Parse::RecDescent::skip = '';

my $text = join("", <STDIN>);
my $grammar = q {

start   : text(s)  /^\Z/
text    : a_link | ignore
ignore  : /[^<]+|<|\n/

a_link  : /<a/i attr(s) '>' /[^<]*/ /<\/a>/i
        {
            # do something with the information
            print "$item[4]\n";
            foreach my $attr (@{$item{'attr(s)'}}) {
                printf "%10s => %s\n", @$attr;
            }
        }

attr    : /\s+/ name  '=' value    
        { 
            [$item{name}, $item{value}] 
        }
name    : /\w+/
value   : "'" /[^']*/ "'"   { $item[2] }
        | '"' /[^"]*/ '"'   { $item[2] }
        | /\S+/             { $item[1] } 

};

my $parser = new Parse::RecDescent($grammar) or die;
defined $parser->start($text) 
    or print "Bad text\n";