in reply to Re^3: Writing to file...
in thread Writing to file...

I am unsure as to what you want. But using the single line that you have give as input, here are several ways to extract the 2nd thing past the "LOCUS" name:
#!/usr/bin/perl -w use strict; my $in = "LOCUS AJ877264 704 bp DNA linea +r INV 15-APR-2005"; my $other_in = " LOCUS AJ877264 "; #=================== # this is a bit "tricky"...$locus is in a list context # if you don't do that then you get True/False value of # the match my ($locus) = ($in=~ m/LOCUS\s+(\w+)/); print "LOCUS=$locus\n"; #PRINTS: #LOCUS=AJ877264 #============== # this does the same thing with spaces in front of LOCUS # in other words, no change is needed... my ($other_locus) = ($other_in=~ m/LOCUS\s+(\w+)/); print "LOCUS=$other_locus\n"; #PRINTS: #LOCUS=AJ877264 #================= # if you want to guarantee that the LOCUS you match is # the first on on line preceded by some possible blanks, # my ($other_locus) = ($other_in=~ m/^\s*LOCUS\s+(\w+)/); # will do it ^ start at beginning of line, then zero or # blanks, then LOCUS, then one or more blanks then a # sequence of "word" characters [0-9A-Za-z_]+ #=================== # This is a "list slice". # split(/\s+/,$in) is put into a list context with () # and the second thing, index [1] is moved to lvalue my $locus_also = (split(/\s+/,$in))[1]; #note "my ($locus_also) =" is also completely fine. print "Another way: LOCUS=$locus_also\n"; #PRINTS: #Another way: LOCUS=AJ877264 #=============== # the split version won't work with spaces in front # of LOCUS as a "" list element will be created: ($locus_also) = (split(/\s+/,$other_in))[1]; print "Another way 2: LOCUS=$locus_also\n"; #PRINTS: #Another way 2: LOCUS=LOCUS ($locus_also) = (split(/\s+/,$other_in))[2]; print "Another way 2: LOCUS=$locus_also\n"; #PRINTS: #Another way 2: LOCUS=AJ877264 #================= #or remove leading spaces, for the split case $other_in =~ s/\s*//; ($locus_also) = (split(/\s+/,$other_in))[1]; print "Another way 2: LOCUS=$locus_also\n"; #PRINTS: #Another way: LOCUS=AJ877264