use strict; use warnings; my $file = 'file.txt'; open(my $fh, '<', $file) or die("Unable to open input file \"$file\": $!\n"); my %hash; while (<$fh>) { chomp; my ($dtype, $rest) = split(/:/, $_, 2); my ($id, $desc) = split(/\t/, $rest, 2); $hash{$id} = $desc; } #### while (<$fh>) { my ($id, $desc) = /^[^:]*:([^\t]*)\t(.*)$/; $hash{$id} = $desc; }