#!/usr/bin/perl use warnings; use strict; my $list = 'foo #comment bar baz'; my ($first, $second, $third) = grep(/^\w+$/, split(' ',$list)); print<<_; 1. $first 2. $second 3. $third _ ; C:\>perl test.pl 1. foo 2. bar 3. baz