#!/usr/bin/perl use strict; use warnings; use Data::Dumper; my %lut; my $file1 = './file1.txt'; my $file2 = './file2.txt'; open(my $fh,"<",$file1) or die $!; while (<$fh>) { chomp; my @cur = split(/;/); push @{$lut{$cur[0]}->{$cur[2]}->{$cur[1]}}, $cur[3]; } close $fh; open(my $fh2,"<",$file2) or die $!; while(<$fh2>){ my ($number,$path) = (split(/,/,$_))[2,3]; my ($path1,$path2) = split(/\//,$path); if(exists $lut{$path1}->{$path2}->{$number}){ my $string = join(" # ",@{$lut{$path1}->{$path2}->{$number}}); print $string,"\n"; } } close $fh2;