#!/usr/bin/perl use warnings; # open a file and assign the filehandle FILE open(FILE, "2.txt") or die("can't open myfile.txt: $!\n"); while() { if($_ =~ /\s+(\S+)\s+(\S+)/) { $hash{$1} = $2; push(@index,$1); push (@a2, $2); } } close(FILE); # close the filehandle #print @a2, "\n"; #foreach$key(@index) #{ #print $key."====>".$hash{$key}."\n"; #} $i=0; open(FILEHANDLE, ">output.txt") or die "cannot open file for reading: $!"; while ($i<= ($#a2 - 1)) { $c1=$a2[$i]; $c2=$a2[$i+1]; $c3=$a2[$i+2]; $c4=$a2[$i+3]; $c5=$a2[$i+4]; $i5 = $index[$i+4]; $c6=$a2[$i+5]; $c7=$a2[$i+6]; $c8=$a2[$i+7]; $c9=$a2[$i+8]; $i++; #print $c5, "\n"; if (($c1<$c2) && ($c2<$c3) && ($c3<$c4) && ($c4<$c5) && ($c5>$c6) && ($c6>$c7) && ($c7>$c8) && ($c8>$c9)) { $peak=$c5; #print $peak, "\n"; print FILEHANDLE "$i5 $peak\n"; } } close (FILEHANDLE);