#!/usr/bin/perl -w use strict; while () { my $string = (split)[2]; # extract the 3rd "word" print "$string\n" if $string =~ /^[gH]/; #output if it begins with a "g" or a "H" } __DATA__ data to gbsdff03dfif7 is data to HR620-Asdf2 data to HP650dfgd-Af452 is