my @strings = qw( /home/usernames/doejohnwilson x/home/usernames/doejanemary ); my $common_length = ( $strings[0] ^ $strings[1] ) =~ /^\0*/ && $+[0]; print substr $strings[0], 0, $common_length;