#! perl -slw use strict; use Inline::Files; use Data::Dumper; my %dates; while () { chomp; my $name = $_; ; while(my $line = ) { last if $line =~ /^\s*$/; my ($start, $end) = $line =~ /^\d+\s+(\d+)\s+(\d+)/; my $data = "$name\t$line"; push @{ $dates{$_} }, \$data for $start .. $end; } } #! print scalar keys %dates; <>; #! Dump the %dates hash. (Data::Dumper blows the stack on structure this large:() #! print "$_:\n @{[ map{ $$_ } @{$dates{$_}} ]}" for keys %dates; ; #! Skip the header line while( ) { my ($ID, $text) = /(\d+),(.*$)/; print "$ID '$text' matches with"; print qq[ @{[ map{ "\t" . $$_ } @{$dates{$ID}} ]} ]; } __END__ __DATAFILE1__ ABC Corp. 1 200210014 200210105 some text description 2 200211011 200212053 some text description 3 200323021 200331234 some text description XYZ Ltd. 1 200210014 200210105 some text description 2 200211011 200212053 some text description CDC Inc. 1 200110014 200110325 some text description 2 200534011 200577234 some text description 3 200212344 200232399 some text description 4 199989987 199999991 some text description __DATAFILE2__ ID,Address,MoreData 200110100,some text here,etc 200918943,some text here,etc 200211015,some text here,etc 199212395,some text here,etc 200110100,some text here,etc 200210100,some text here,etc