for(glob("*.gz")){ my @o = `zcat $_ | sed 's/[<> ]//g'`;chomp @o;push @l,@o; } my %h = map { $_, 1 } @l; #### - line1 xxxxx - line2 yyyyy - line3 zzzzz #### - file1_line1 xxxxx - file1_line2 yyyyy - file1_line3 zzzzz - filen_line1 xxxxxxx - filen_line2 yyyyyyy - filen_line3 zzzzzzz #### xxxxx -> 1 yyyyy -> 1 zzzzz -> 1 xxxxxxx -> 1 yyyyyyy -> 1 zzzzzzz -> 1