in reply to help requested with collating data from two files

The remaining issue will be that 1.10.l0 also matches lines that match 1.10.1040 To resolve this try something like the following
use strict; use warnings; open(my $data_1 ,"<", "data1.dat"); my %stubs; while (<$data_1>){ chomp; $stubs{$_}=0; } close $data_1; open(my $data_2 ,"<", "data2.dat"); while (<$data_2>){ chomp; for my $stub (reverse sort keys %stubs){ if ($_=~ /\Q$stub\E/){ $stubs{$stub}++; last } } } for my $stub (sort {$stubs{$a} <=> $stubs{$b}} (keys %stubs)){ printf "%-10s: %d\n",$stub, $stubs{$stub}; } __OUTPUT__ 1.10.220 : 1 1.10.1040 : 1 1.10.10 : 3 1.10.150 : 3
By using the reverse sort on the keys of %stubs you can guarantee a "longest match only"

print "Good ",qw(night morning afternoon evening)[(localtime)[2]/6]," fellow monks."