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


in reply to Find common prefix from a list of strings

An alternative:
@files = qw(model4run1 modexl2run1 model4run2 model1run1); my @array = split //,shift @files; my @prefix; foreach (@files) { @prefix = (); while ($c = shift @array) { next unless /^$c/; s/^$c//; push @prefix,$c; } @array = @prefix; } print join ""=>@prefix,"\n";