Hi,
It is generally not recommended to use regex matches to parse HTML files.
Instead as swkronenfeld pointed out its better to use the CPAN module HTML::Parser
Below is an example of its usage.
#!/usr/bin/perl
use Modern::Perl;
use autodie;
use HTML::Parser ();
my $p = HTML::Parser->new(
start_h => [\&start, 'tagname, attr'],
);
open my $fh, '<', shift;
$p->parse_file($fh);
$fh->close;
sub start {
my ($tag_name, $attrs) = @_;
return unless $tag_name eq 'div';
say 'sample Text' if exists $attrs->{class}
and $attrs->{class} and $attrs->{class} =~ /^lastUnit.
+*/;
}
-Kiel