#!/usr/bin/perl use warnings; use strict; use Data::Dumper; my ( $broken, $works ); my @list = qw( this that another ); for ( @list ) { $broken->{'this'} = $_ eq 'this' ? 1 : 0; $broken->{'that'} = $_ eq 'that' ? 1 : 0; $broken->{'another'} = $_ eq 'another' ? 1 : 0; } for ( @list ) { $works->{'this'} = 1 if $_ eq 'this'; $works->{'that'} = 1 if $_ eq 'that'; $works->{'another'} = 1 if $_ eq 'another'; } print Dumper $broken, $works; #### perl example.pl $VAR1 = { 'another' => 1, 'that' => 0, 'this' => 0 }; $VAR2 = { 'another' => 1, 'that' => 1, 'this' => 1 };