while() { my $line=$_; my $index= index($line, "\s"); my $word= substr $line, 0, $index; print $word; }