#!/usr/bin/perl use warnings; use strict; my $str0 = "C:/Build~~/Win/App/Experiments/1_0/"; my $str1 = "${str0}Experiments/Blood Pressure/_pieces"; my $str2 = "${str0}temp/Blood Pressure/_pieces"; ($str0 ^ $str1) =~ /^\0*/; my $commonLen = $+[0]; my $commonStr = substr $str1, 0, $commonLen, ""; substr $str2, 0, $commonLen, ""; print "Common: $commonStr\n"; print "Tail 1: $str1\n"; print "Tail 2: $str2\n"; #### Common: C:/Build~~/Win/App/Experiments/1_0/ Tail 1: Experiments/Blood Pressure/_pieces Tail 2: temp/Blood Pressure/_pieces