That is JSON. So use the JSON module to parse it:
use JSON;
my $json = decode_json ( $response -> content );
foreach my $element ( @{ $json -> {ResultSet} -> {results} } ) {
print $element -> {url},"\n";
}
Fuller; runnable example:
#!/usr/bin/perl
use strict;
use warnings;
use JSON;
use Data::Dumper;
my $json_str = '{
"ResultSet": {
"result": [
{
"rank": "999999",
"term": "shampoo"
},
{
"rank": "999999",
"term": "Beauty",
"url": "/search/results.jsp?Ntt=shampoo&N=359434"
},
{
"rank": "999999",
"term": "Baby, Kids & Toys",
"url": "/search/results.jsp?Ntt=shampoo&N=359449"
}
]
}}';
my $json = decode_json($json_str);
print Dumper $json;
foreach my $element ( @{ $json->{ResultSet}->{result} } ) {
print $element ->{url}, "\n" if $element->{url};
}
In the above, $json_str fills the niche of your content. I've made the assumption that you have plain text, and the output above is the result of print Dumper \$content.
This thus prints:
$VAR1 = {
'ResultSet' => {
'result' => [
{
'rank' => '999999',
'term' => 'shampoo'
},
{
'rank' => '999999',
'term' => 'Beauty',
'url' => '/search/results.jsp?Ntt=shampoo&N=359434'
},
{
'url' => '/search/results.jsp?Ntt=shampoo&N=359449',
'term' => 'Baby, Kids & Toys',
'rank' => '999999'
}
]
}
};
/search/results.jsp?Ntt=shampoo&N=359434
/search/results.jsp?Ntt=shampoo&N=359449
Dumper($scalar)orDumper(\$scalar)?JSON, which looks suspiciously similar to theDumperoutput, but isn't quite the same formatting.Dumperoutputs.