use strict; use warnings 'all'; use constant { EMAIL => 17, CONTACTME => 27, SKUTITLE => 34 }; my @records; # Arrays are initialised empty; no need to do it explicitly. push @records, [ split "\t" ] for <>; do { tr/"//d for @$_ } for @records; my @contact_records; do { push @contact_records, [ @$_[ SKUTITLE, CONTACTME, EMAIL ] ] if $_->[CONTACTME] == 1 } for @records; { local $, = "\t"; local $\ = "\n"; print @$_ for sort { $a->[0] cmp $b->[0] } @contact_records; }