Simple examples to open a file for reading: open(my $fh, "<", "input.txt") or die "Can't open < input.txt: $!"; and for writing: open(my $fh, ">", "output.txt") or die "Can't open > output.txt: $!";