my $update_p4filelog = "...xyz branch from //source/qcom/qct/multimedia/qtv/player/audioplayer/rel/1.1/src/file.cpp#1,#8"; my ($path, $ver) = $update_p4filelog =~ /branch from (.*\/.*)[#\d+,]?(#\d+)$/; my $update_base_branched_p4path = "$path$ver"; print "$update_base_branched_p4path\n";