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


in reply to Re: Find common prefix from a list of strings
in thread Find common prefix from a list of strings

I liked this one, but why would you use a grep there..? Also, metacharacters in $p will break it.
sub maxprefix { my $p = shift; for (@_) { chop $p until /^\Q$p/ } return $p; }
Depending on the nature of your data this might be a win:
sub maxprefix { my $s = reverse shift; my $p = ''; for (@_) { $p .= quotemeta chop $s while /^$p/ } chop $p; return $p; }

Makeshifts last the longest.