use Data::Dumper; my %all_entry; while () { chomp; next unless (/^>/); my $line = $_; $line =~ />.*\{GI=(\d+),(\w+),(\d+\-\d+)\}/g; # 'g' doesn't seem to work #print "$line --- $1 $str{$2} $3\n"; push @{ $all_entry{$1}{$2} }, $3; } print Dumper \%all_entry; __DATA__