#!/usr/bin/perl -w use strict; use warnings; my $hash_ref1 = { this => 'blarney', some => 'foo', chancy => 'at best', }; my $hash_ref2 = { this => 'that', some => 'thing', another => 'something', }; print "this is $hash_ref2->{this}\n"; my @a = ($hash_ref1, $hash_ref2); my $test = sub {$_->{this} eq 'that'}; foreach (@a) { if ($_->{this} eq 'that') { print qq{I only want to see case where: "this really does equal $_->{this}"\n}; } if ($test->()) { print "this really does equal $_->{this}\n\n"; } }