You do not want to be parsing HTML
using regular expressions. Using a regular expression will sooner or later falsify your data in this case. You'll be far better off using a module to do this for you.
In this example we are using HTML::TreeBuilder
and List::Util
. If you're wanting the highest in each category, another way to do this is using TreeBuilder::XPath to query all in specific sections.
use strict;
use warnings;
use HTML::TreeBuilder;
use List::Util qw( max );
my $data
= '<a href="/planes-desktop-wallpapers/page/8">8</a>\n'
. '<a href="/planes-desktop-wallpapers/page/9">9</a>\n'
. '<a href="/planes-desktop-wallpapers/page/10">10</a>'
;
my $tr = HTML::TreeBuilder->new_from_content($data);
my @vals =
map { [ $_->attr('href'), $_->content_list ] }
max ( $tr->look_down( _tag => 'a') );
use Data::Dumper;
print Dumper \@vals;
__OUTPUT__
$VAR1 = [
[
'/planes-desktop-wallpapers/page/10',
'10'
]
];
If you want just the text (number) instead just do:
my @vals = map { $_->content_list } max ( $tr->look_down( _tag => 'a') );