my @strings = ( 'string that I need to gather the common base from: number 1 and some other junk in it', 'string that I need to gather the common base from: number 2 and some other junk in it', 'string that I need to gather the common base from: number 3 and some other junk in it' ); #After processing, I should get: #'string that I need to gather the common base from: number ' my $string = ''; my ($match_string, @rest_strings) = @strings; for my $string_idx (0..length($match_string)){ if(scalar(@rest_strings) > (grep { substr($match_string, $string_idx, 1) eq substr($_, $string_idx, 1) } @rest_strings)){ $string = substr($match_string, 0, $string_idx); last; } }