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

technojosh has asked for the wisdom of the Perl Monks concerning the following question:

I have a group of strings, that all share a common beginning substring. This substring will not always be identical, the only thing I know is that in any given array of strings, there *will* be a common substring at the beginning.

Context: As of today, I have a reporting script that will produce an HTML table, row-by-row, of a set of tests. I want to show a "header" row, that displays the test category, and this is found in the substring problem I mention above.

Two example sets of strings:

my @array_of_test_names = ( 'History - Family History - Suite with Patient - Clinic - Select R +emove(-) Icon of Relative. - Clinic', 'History - Family History - Suite with Patient - Clinic - Save aft +er Entering values in all fields - Clinic', 'History - Family History - Suite with Patient - Clinic - Select A +dd(+) Icon of Relative. - Clinic', 'History - Family History - Suite with Patient - Clinic - Multiple + selection of relatives - Clinic', 'History - Family History - Suite with Patient - Clinic - Interact +ion Checking message not provided if procedure code is selected - Cli +nic', 'History - Family History - Suite with Patient - Clinic - Interact +ion Checking message provided if no procedure code is selected - Clin +ic' ); my @second_sample_array = ( 'WorkCenter - List Patients - To check the items displayed in Filt +er By combo box', 'WorkCenter - List Patients - To check Filter By combo box when no + patients are assigned on initial login', 'WorkCenter - List Patients - Order in which patients are displaye +d' );

Any guidance on how to capture a common beginning substring would be greatly appreciated.