if ($SIRtrue && !($_ =~ /SPECint_base/)){ $SIR{$_}=$_; } if ($SFRtrue && !($_ =~ /SPECfp_base/)){ $SFR{$_}=$_; } #### use strict; use warnings; use Data::Dumper; my $str = <){ chomp; if (/SPECint_base/){ $SIRtrue = 1; $SFRtrue = 0; next; } elsif (/SPECfp_base/){ $SIRtrue = 0; $SFRtrue = 1; next; } if ($SIRtrue)){ push( @{$SIR{SPECint_base}}, $_ ); } elsif ($SFRtrue){ push( @{$SFR{SPECfp_base}}, $_ ); } } print Dumper(\%SIR); print Dumper(\%SFR); #### $VAR1 = { 'SPECint_base' => [ '1', '2', '3' ] }; $VAR1 = { 'SPECfp_base' => [ '4', '5', '6' ] };