use strict; use warnings; #<<-- warnings print "\n Enter The file name :>"; chomp( my $filename1 = ); open( FILE, "<", $filename1 ) or die "\n...Cannot find the file: $filename1"; #<<-- $filename1" open( W, "> Result.txt" ); my @line; while () { push( @line, $_ ); my $count++; } print W $line[0]; for ( my $i = 0 ;$i < $count ;$i++ ) #<<-- my $i; $count, from above, has dropped outside of scope and is now undefined. Update: use $i < $#line+1 { my @st = split( ' ', $line[$i] ); #<<-- my @st if ( ( $st[4] eq /chr1/ ) && ( $st[10] eq /chr1/ ) ) { print W $line[$i]; } }