in reply to Question related to map

In general, using a foreach loop combined with a push will be clearer, however, you can do this fairly simply using map and the Conditional Operator (? :)

#!/usr/bin/perl use strict; use warnings; my @ms = ( {a => 'x1', b => 'y', c => 'z1'}, {a => 'x2', b => 'y1', c => 'z2'}, {a => 'x3', b => 'y', c => 'z3'}, {a => 'x4', b => 'y2', c => 'z4'}, ); my @list = map {$_->{b} eq 'y' ? $_->{a} : () } @ms; print join "\n", @list;