#UNTESTED use strict; use warnings; my %files = ( FOO => { A => 2 }, BAR => { B => 3 } ); MAIN: while () { my ($col1, $col2) = split m/\s+/; foreach my $file (keys %files) { if (exists $files{$file}{$col2} ) { #do something; next MAIN; } } }