#!/usr/bin/perl use strict; use warnings; my @array_of_test_names = ( 'History - Family History - Suite with Patient - Clinic - Select Remove(-) Icon of Relative. - Clinic', 'History - Family History - Suite with Patient - Clinic - Save after Entering values in all fields - Clinic', 'History - Family History - Suite with Patient - Clinic - Select Add(+) Icon of Relative. - Clinic', 'History - Family History - Suite with Patient - Clinic - Multiple selection of relatives - Clinic', 'History - Family History - Suite with Patient - Clinic - Interaction Checking message not provided if procedure code is selected - Clinic', 'History - Family History - Suite with Patient - Clinic - Interaction Checking message provided if no procedure code is selected - Clinic', ); my @second_sample_array = ( 'WorkCenter - List Patients - To check the items displayed in Filter 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 displayed', ); sub getleastcommonprefix { my @searcharray = @_; my $common = $searcharray[0]; foreach my $index (1 .. $#searcharray) { $_ = $searcharray[0] . reverse $searcharray[$index]; m/(.*)(.*)(??{quotemeta reverse $1})/s; if (length $1 < length $common) { $common = $1; } } ## end foreach my $index (1 .. $#searcharray) return $common; } ## end sub getleastcommonprefix print 'Common prefix for first sample [' . getleastcommonprefix(@array_of_test_names) . "]\n"; print 'Common prefix for second sample [' . getleastcommonprefix(@second_sample_array) . "]\n";