#!/usr/bin/perl -w #decided to have input file entered in command line #####INPUT Name of multiple seq file, open file and assign IN filehandle ############# unless(@ARGV==1) {die "please provide file name in command line \n file should contain multiple sequences in fasta format \n\n";} $filename=$ARGV[0]; open(IN, "< $filename") or die "cannot open $filename:$!"; ################################################## $flag=0; #flag0 : still looking for first seq file annotation line while (defined ($line=)){ # read through file line by line if ($line=~/^>/) { #look for beginning of line starting with > (^ is an anchor for the beginning of the line) # do this loop only if annotation line encountered. $line =~ m/gi\|(\d+)\|/; #match gi|number capture number in $1 $outname = "gi_".$1.".sfa"; # make useful name for outfile print "\n\noutname: $outname\n"; #print outname to screen :) if ($flag==1){close OUT}; # if this is the 2nd time around, close the 1st OUT open(OUT, ">$outname")||die "cannot open: $!"; #open file fith $outname and assign handle OUT $flag=1; #OUT is open }; print "$line"; #print to screen print OUT "$line"; #print to OUT } close(IN); close(OUT);