use Modern::Perl; use Number::Range; use Text::CSV::Auto qw( process_csv ); use Data::Dump qw /dump/; my $debug = 0; my %database; process_csv('./primary.txt', sub { my $row = shift; push @{$database{$row->{name}}}, [$row->{start}, $row->{end}]; } ); say dump(\%database) if $debug; analyse ('./secondary_1.txt'); analyse ('./secondary_2.txt'); sub analyse { my $file = shift; say "--Checking $file--"; my %data; process_csv($file, sub { my $row = shift; push @{$data{$row->{name}}}, [$row->{start}, $row->{end}]; } ); say dump(\%data) if $debug; for my $name (sort keys %database) { unless ($data{$name}) { for my $range_ref (@{$database{$name}}) { say "$name: $range_ref->[0] $range_ref->[1] absent 0 0"; } next; } for my $range_ref (@{$database{$name}}) { print "$name: $range_ref->[0] $range_ref->[1] "; my $range = Number::Range->new($range_ref->[0] .. $range_ref->[1]); for my $testrange_ref (@{$data{$name}}) { if ($range->inrange(@$testrange_ref)) { print "present $testrange_ref->[0] $testrange_ref->[1] "; } else { print "absent 0 0 "; } } print "\n"; } } say '------------------------------'; } #### --Checking ./secondary_1.txt-- Alex: 3 44 absent 0 0 absent 0 0 Alex: 124 175 absent 0 0 present 134 155 Barry: 2 44 present 12 24 Drew: 9 43 absent 0 0 James: 6 45 absent 0 0 ------------------------------ --Checking ./secondary_2.txt-- Alex: 3 44 absent 0 0 Alex: 124 175 present 154 174 Barry: 2 44 absent 0 0 Drew: 9 43 present 19 54 absent 0 0 James: 6 45 present 29 45 ------------------------------