#!/usr/bin/perl -w
use strict;
use HTML::TokeParser;
# get the file name to parse from the command line
my $html = shift or die 'Specify a file name';
# access the file with the parser
my $p = HTML::TokeParser->new($html) or die $!;
# loop through all tokens
while (my $r = $p->get_token) {
# $r->[0] tells us if it's a Start tag, End tag, Text, Comment
# for start tags, $r->[1] tells us the type of tag
# only process META start tags
next unless $r->[0] eq 'S' && $r->[1] eq 'meta';
print "Found tag\n";
# $r->[2] is a hash ref containing attributes and values
while (my ($k,$v) = each %{$r->[2]}) {
print "\t$k = $v\n";
}
}