use strict; use warnings; # please note the 'sign' ">" open( my $fh, ">", "output_file.txt" ) or die "cannot open output_file. +txt$!"; open( my $file, "<", "/file.txt" ) or die "cannot open < file.txt $!"; while (<$file>) { unless (/^A/) { # please note "$fh" filehandle to write to print $fh $_; } } close $file or die $!; close $fh or die $!;