#!/usr/bin/perl -w use strict; # Use undef hash values for unneeded fields my @fields = ( 'FIRSTNAME', 'LASTNAME', 'PHONE', undef, # Useless data undef, # Useless data undef, # Useless data 'FAX', undef, # Useless data 'CITY', 'STATE', ); # Use dummy key for unneeded fields my @fields2 = ( 'FIRSTNAME', 'LASTNAME', 'PHONE', 'DUMMY', # Useless data 'DUMMY', # Useless data 'DUMMY', # Useless data 'FAX', 'DUMMY', # Useless data 'CITY', 'STATE', ); while () { chomp; my (%record, %record2); # Using undef keys; requires disabling warnings # about uninitialized values in hash slice no warnings; @record{@fields} = split(/\t/, $_); print "1) First Name: $record{FIRSTNAME}, State: $record{STATE}\n"; # Using dummy key, then deleting it use warnings; @record2{@fields2} = split(/\t/, $_); delete $record2{'DUMMY'}; print "2) First Name: $record2{FIRSTNAME}, State: $record2{STATE}\n"; } print "\n---------------\nDone.\n"; exit; __DATA__ Bill Davis 999-888-7777 KH101 1 1 999-888-7770 1965 Chantilly VA Bob Rogers 999-777-8888 KH101 1 1 999-777-8880 1953 Dallas TX Jim Dawson 999-787-8787 KH101 1 1 999-787-8787 1972 San Diego CA Harry Jones 999-878-7878 KH101 1 1 999-878-7870 1963 Chicago IL John Black 999-778-7788 KH101 1 1 999-778-7788 1936 Topeka KS