#!/usr/bin/perl -w use strict; use HTML::TokeParser; # Regex representing the list of acceptable tags my $ok_stuff = qr/^(p|br|h.|font|pre)$/; # Some test html. my $html = "


Testing

\n"; # Instantiate the TokeParser my $parser = new HTML::TokeParser (\$html); # Loop until all tokens are read while (my $token = $parser->get_token()) { # Immediately print any "text" token if ($token->[0] eq "T") { print $token->[1]; } # Check all other tokens against the regex before printing elsif ($token->[1] =~ $ok_stuff) { print $token->[$#{$token}]; } }