$ cat u.pl my $data = "Region Item volume Month"; my %h = do {my $cnt=0; map {$_=>++$cnt} split /\s+/, $data}; print "$_ $h{$_}\n" for grep {exists $h{$_}} qw(Item volume Tuba); $ perl u.pl Item 2 volume 3