use strict;
use warnings;
#use this we improve the conditional test by not looking at lenght but real contents of a scalar--regular expression--or simply pattern

my $file="example.fasta";
open (FILEHANDLE,$file); 
my @array=<FILEHANDLE>;
close FILEHANDLE;

while (@array)
{
my $temp=shift @array;
chomp $temp; 
#test if it matches some pattern: $s=~ m/(pattern1)/; m can be missed--matching is default by perl regular expression. 
if($temp=~ m/\>/)
#try if there is a ">" symbol--symbol in perl must be prepositioned by "\"--even "\" itself so it would be "\\" if you look for "\"
{
print $temp, "\n"; 
print "this is one line of ID\n"; 
}
else
{
#let's substitute the sequence A by a: $s=~ s/pattern1/pattern2/; changing pattern1 to pattern1; 
$temp=~ s/A/a/;
print $temp, "\n";
#but it only changes A once; for the whole substitution, use translate: $s=~ tr/pattern1/pattern2/; or you say $s=~ s/pattern1/pattern2/g, g means "global"--please check regular expression options for confining matching and so on... 
$temp=~ tr/A/a/;
print $temp, "\n";

#you can translate all at same time: T to A, C to G, G to C; 
$temp=~ tr/TCG/AGC/;
print $temp, "\n"; 
}
}



#regular expression can also be used to separate stuff, e.g. if sequence ID is gi|number|gb|accession, you can use split by | and gives back an array;
my @ele=split /\|/, "gi|number|gb|accession"; 
print @ele, "\n";

#alternatively some complex match and extract scalars as well: 
my $id= "gi|number|gb|accession"; 
$id=~ m/\w+(\|\d+)(\|\w+)(\|\w+\d+)/; 
#this is complex combination of regular expressions--please refer to "wild cards" and "options of regular expression"--regular expression is a science by itself... 
print $1, " ", $2, " ", $3, "\n"; 
#this will print all the elements that match the pattern given by (\|\d+), (\|\w+), (\|\w+\d+)
