use strict; use warnings; my $datafile = 'data.txt'; open( my $fh, $datafile ) or die "Cannot open '$datafile' for reading: $!\n"; my %items; while ( defined( my $line = <$fh> ) ) { chomp( $line ); $line =~ s/[\r\n]*$//; my @values = split /--/, $line; @items{ @values } = undef; } close $fh; # At this point, you have %items, which is a lookup table.