my $p = HTML::TokeParser->new($file) || die "Can't open: $!"; my $head = {}; # Behälter für head-Tags while (my $token = $p->get_token) { # Abbruch bei Erreichen des body-Tags if( $token->[0] eq "S" and $token->[1] eq 'body' ){ last; } #print Data::Dumper::Dumper($token); # css_link if( $token->[0] eq "S" and $token->[1] eq 'link' and $token->[2]->{'rel'} eq 'stylesheet' ){ push @{$head->{'css_link'}}, $token->[4]; } # meta if( $token->[0] eq "S" and $token->[1] eq 'meta' ){ push @{$head->{'meta'}}, $token->[4]; } # title if( $token->[0] eq "S" and $token->[1] eq 'title' ){ $head->{'title'} = $p->get_trimmed_text("/title"); } # css_style if( $token->[0] eq "S" and $token->[1] eq 'style' ){ push @{$head->{'css_style'}}, $p->get_trimmed_text("/style"); } # js_script if( $token->[0] eq "S" and $token->[1] eq 'script' and exists($token->[2]->{'language'}) and $token->[2]->{'language'} =~ /JavaScript/i ){ push @{$head->{'js_script'}}, $p->get_trimmed_text("/script"); } } print Data::Dumper::Dumper($head);