while (<$FILE>){ # Don't need to use a $line variable; leave it in $_ next if /^c\s/; # Skip comments $_ = (split /\$/)[0] # Throw away everything to the right of $ (if any) # I'm not sure from your description if this is the pattern you want; I'm guessing foreach my $datum (/ (\w+\.\w\wc) /gx ){ push(@data, $datum)}} # This could be made terser #### $array=@array; for ( $i=1; $i<$array; $i=$i+2) #### for ( $i=1; $i < @array; $i=$i+2)