#!/usr/bin/perl use strict; # https://perlmonks.org/?node_id=11110672 use warnings; my $summary = ; while( ) { /./ or next; my $xor = "$_" ^ "$summary"; substr $summary, $-[0], 1, '*' while $xor =~ /[^\0]/g; } print $summary; __DATA__ a/b/c/p0/m0/b0/r_a_c1_0/q a/b/c/p0/m0/b0/r_a_c1_1/q a/b/c/p0/m0/b0/r_a_c1_2/q a/b/c/p0/m0/b1/r_a_c1_0/q a/b/c/p0/m0/b1/r_a_c1_1/q a/b/c/p0/m0/b1/r_a_c1_2/q #### a/b/c/p0/m0/b*/r_a_c1_*/q