__DATA__ >r4713.1 |SOURCES={GI=162960844,bw,7184325-7184361} >r4714.1 |SOURCES={GI=162960844,fw,6257219-6257255} #### # note that there can me more than two "GI"s inside the {} bracket __DATA__ >r7.1 |SOURCES={GI=162960844,bw,0-4;GI=162960844,bw,9025576-9025608}| >r6.1 |SOURCES={GI=152989753,bw,0-30;GI=152989753,bw,1877925-1877931}| #### 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__