my @headers; my @header_present=" "; #clearing the data here if ($line =~ /.\data/) { push @header_present,grep( (/\Q$line\E/i), @headers); if(@header_present)#this is always true,the value pushed above gets stuck,how to clear the array when it executes next time? { }