http://www.perlmonks.org?node_id=274246


in reply to Find common prefix from a list of strings

Wanting the common prefix makes for a nifty shortcut. Sort the strings alphabetically and you only need to compare the first and last of them,

sub common_prefix { my ($first, $last) = (sort @_)[0,-1]; my $i = 0; while (substr($first, $i, 1) eq substr($last, $i, 1)) { $i++} substr $first, 0, $i; }

After Compline,
Zaxo