##ALSO UNTESTED while () { my ($col1, $col2) = split m/\s+/; stuff_i_need_do($col1) if ( check_for_condition(\%files,$col2) ); } sub check_for_condition { my $files = shift || return undef; my $col = shift || return undef; foreach my $file ( keys %{$files} ) { return 1 if (exists $files{$file}{$col2} ); } return undef; } sub stuff_i_need_to_do { my $stuff = shift; #do something; }