use strict; use warnings; 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', ); my $sep = "\0"; my $nosep = "[^$sep]"; my $all = join $sep, @strings; $all =~ /^ ($nosep*) $nosep*? ( $sep \1 $nosep*? )+ $/x; print "solution: '$1'";