my $path = "C:/Documents and Settings/aldaihi/Desktop/Monks"; open (my $fh, '<',"$path/genes.txt") or die ("could not open file $!\n"); open (my $rfh,'>',"$path/results.txt") or die ("could not open file $!\n"); my $firstLine = <$fh>; print $rfh $firstLine; while(<$fh>){ chomp; if(/(?=Withdrawn)/i){ #U can do things to the line in here #..... # split or rearrange .. # print $rfh $_,"\n"; } }