A ,AA ,AAA ,AAAA ,AAAAA , #### T ,TT ,TTT ,TTTT ,TTTTT , #### G ,GG ,GGG ,GGGG ,GGGGG , #### #!/usr/bin/perl use warnings; @apple=(1 ... 3); $nm=0; foreach my $num (@apple) {$nm++; $output_fle="$nm.txt"; if (-e $output_fle) { open FILE,"$output_fle" or die "Couldn't open file: $!"; $fle=join(" ",); close FILE; $fle=~ s/\s//g; @fle=split(' ',$fle); push @all_file,@fle; } # End of if LOOP for required files: } # Last curly brace of Foreach LOOP for uploading all files: ######################### # Code for each file: ## ######################### $file_no=0; foreach my $each_fle ( @all_file) { $file_no++; @a=split(',',$each_fle); $seq_no=0; foreach my $seq (@a) { $seq_no++; # For each sequence of the file $seq=~ s/,//g; $seq= uc$seq; $seq_len=length($seq); # For testing print"\n Element $seq_no of File $file_no: $seq Length: $seq_len\n"; # push length & each seq to an array: push @names,$seq; push @values,$seq_len; } # End of foreach LOOP for each file: ####################################################### # Find two lowest & two highest values of each file with sequences: ####################################################### use 5.010; use Data::Dumper; use constant IWANT => 2; my @data; my $pos=1; for my $val (@values) { my $name=shift @names; my $rec=sprintf"\n Length %0.1f; Seq: %s",$val,$name; push @data,$rec;} print"\n\nLength (Small to big) with sequences for File $file_no:\n"; @data= sort @data; for(0 .. IWANT-1) {say $data[$_];} print"\n"; print"\nLength (Big to small) with sequences for File $file_no:\n"; for (1 .. IWANT) {say $data[-$_];} ############################ # End Max & Min codes here: ############################# @values=(); # To empty the array @names=(); # To empty the array print"\n######## File $file_no ends ##############\n\n"; } # End of foreach LOOP for all files exit; ######################################## #### Microsoft Windows [Version 6.1.7601] Copyright (c) 2009 Microsoft Corporation. All rights reserved. C:\Users\x>cd desktop C:\Users\x\Desktop>test.pl Element 1 of File 1: A Length: 1 Element 2 of File 1: AA Length: 2 Element 3 of File 1: AAA Length: 3 Element 4 of File 1: AAAA Length: 4 Element 5 of File 1: AAAAA Length: 5 Length (Small to big) with sequences for File 1: Length 1.0; Seq: A Length 2.0; Seq: AA Length (Big to small) with sequences for File 1: Length 5.0; Seq: AAAAA Length 4.0; Seq: AAAA ######## File 1 ends ############## Element 1 of File 2: T Length: 1 Element 2 of File 2: TT Length: 2 Element 3 of File 2: TTT Length: 3 Element 4 of File 2: TTTT Length: 4 Element 5 of File 2: TTTTT Length: 5 Length (Small to big) with sequences for File 2: Length 1.0; Seq: T Length 2.0; Seq: TT Length (Big to small) with sequences for File 2: Length 5.0; Seq: TTTTT Length 4.0; Seq: TTTT ######## File 2 ends ############## Element 1 of File 3: G Length: 1 Element 2 of File 3: GG Length: 2 Element 3 of File 3: GGG Length: 3 Element 4 of File 3: GGGG Length: 4 Element 5 of File 3: GGGGG Length: 5 Length (Small to big) with sequences for File 3: Length 1.0; Seq: G Length 2.0; Seq: GG Length (Big to small) with sequences for File 3: Length 5.0; Seq: GGGGG Length 4.0; Seq: GGGG ######## File 3 ends ############## #### Two shortest strings (small to big): Seq 1: ATG seq 2: AATTGG Two longest strings (big to small): seq 1: AAAAATTTTTGGGGG seq 2: AAAATTTTGGGG