my $test = sub {$_[0]->{this} eq 'that'}; foreach my $hash_ref (@a) { if ($hash_ref->{this} eq 'that') { print qq{I only want to see case where: "this really does equal $hash_ref->{this}"\n}; } if ($test->($hash_ref)) { print "this really does equal $hash_ref->{this}\n\n"; } }