sub in_common { my $all = join '', scalar( reverse $_[ 0 ] ), @_[ 1 .. $#_ ]; my $offs = length $_[ 0 ]; my $minpos = 0; return grep { my $pos = index( $all, $_, $offs-- ); $pos >= $minpos++; } split //, $_[ 0 ]; }