use strict; use warnings; my $s = do {local $/=undef; }; use XML::Simple; my $data = XMLin("$s", KeepRoot => 0); #use Data::Dumper; #print Dumper $data; my $search_string = "dog cat cow"; # from input my %searchwords = map { $_ => undef } split ' ', $search_string; while( my ($k, $h) = each %$data ){ my $score = scalar grep( exists $searchwords{$_}, split(/, /, $h->{words}) ); # do whatever based on score. } __DATA__ c:\data\cat.xml dog, cat, fish, bird c:\data\cow.xml dog, cat, fish, bird, cow, goat c:\data\snake.xml dog, cat, fish, bird, snake, orange