use warnings; use strict; my %hash = ( 'Key1' => 'Cat.Mouse.Game.Lion.Tiger.Elephant', 'Key2' => 'Cat.Mouse.Game.Lion.Tiger.Lion', 'Key3' => 'Cat.Mouse.Game.Lion.Tiger.Monkey', ); while ( my $data = ) { chomp($data); my $value = join '.' => ( split /[\s.]/, $data )[ 1 .. 3 ]; print map { "$data ($_)\n" if $hash{$_} =~ /$value/ } keys %hash; } __DATA__ Pigeon.Lion.Tiger.Elephant SOME_DATA Pigeon.Lion.Tiger.SeaLion SOME_DATA Pigeon.Lion.Tiger.Monkey SOME_DATA