>perl -wMstrict -le "my @set = ('abc.def.ghi', 'abc', '...'); ;; for my $p (@set) { for my $q (@set) { print qq{'$p', '$q' common at start? }, $q =~ m{ \A \Q$p\E }xms || $p =~ m{ \A \Q$q\E }xms ? 'yes' : 'no'; } } ;; print ''; for my $p (@set) { for my $q (@set) { print qq{'$p', '$q' common at start? }, 0 == index($p, $q) || 0 == index($q, $p) ? 'yes' : 'no'; } } " 'abc.def.ghi', 'abc.def.ghi' common at start? yes 'abc.def.ghi', 'abc' common at start? yes 'abc.def.ghi', '...' common at start? no 'abc', 'abc.def.ghi' common at start? yes 'abc', 'abc' common at start? yes 'abc', '...' common at start? no '...', 'abc.def.ghi' common at start? no '...', 'abc' common at start? no '...', '...' common at start? yes 'abc.def.ghi', 'abc.def.ghi' common at start? yes 'abc.def.ghi', 'abc' common at start? yes 'abc.def.ghi', '...' common at start? no 'abc', 'abc.def.ghi' common at start? yes 'abc', 'abc' common at start? yes 'abc', '...' common at start? no '...', 'abc.def.ghi' common at start? no '...', 'abc' common at start? no '...', '...' common at start? yes