my %dont_want = map {$_=>undef} @columns; while (<$file>){ my @arr = split; print @arr[map {!exists $dont_want{$_}}0..$#arr],"\n"; }