my %ref = ... ; ## Data::Dump::dd(%ref) output here my @probes = ... ; ## Data::Dump::dd(@probes) output here ## foreach my $key ( sort keys %ref ) { #intended function print OUT $ref{$key} . "\t" . $probes[$key]; #testing my @temp = split "\t", $ref{$key}; foreach (@temp) { if ( $temp[0] == 2 ) { print $key. "\t" . $ref{$key} . "\t" . $probes[$key]; } } } ## foreach my $key ( sort keys %ref ) { print OUT $ref{$key} . "\t" . $probes[$key]; my @temp = split "\t", $ref{$key}; foreach (@temp) { if ( $temp[0] == 2 ) { print $key. "\t" . $ref{$key} . "\n"; } } }