my %file_data; open( my $fh, '<', "/path/to/file2" ) or die $!; while(<>) { chomp; $file_data{$_} = $.; } close $fh;