#!/usr/bin/perl -w use strict; my $datafile = shift; my $want_col = shift; open my $fh, '<', $datafile or die "$datafile: $!"; my $headings = <$fh>; chomp $headings; my @columns = split /\t/, $headings; my %column; @column{ @columns } = 0 .. $#columns; die "Column '$want_col' not in $datafile" unless exists $column{ $want_col }; while ( <$fh> ) { chomp; print join "\t", (split /\t/)[ $column{ $want_col } ], "\n"; }