#!usr/bin/perl
use strict;
use warnings;
my $infile = '/path/path/data.txt';
open( my $in, "<", $infile ) # use filehandles not bareword
or die "Couldn't open $infile: $!";
chomp(my @lines = <$in>); # store data in an array in case you need them
close $in
or warn "close failed: $!"; # close file
# empty file
# open file in write mode
# write your new data on empty file
# close file
# done :D
####
An older style is to use a bareword as the filehandle, as
open(FH, "<", "input.txt")
or die "Can't open < input.txt: $!";
Then you can use FH as the filehandle, in close FH and and so on. Note that it's a global variable, so this form is not recommended in new code.
####
It is global to all the script you write so if anyone uses the same name (IN or OUT in our example) those will clash with yours.
It is also harder to pass these variables to functions, than to do the same with regular scalar variables.