You can't do it directly. You have to read the file into a string.
use strict;
use warnings;
use File::Slurp;
my $s = read_file(q{filename.txt});
$s =~ s/expression/replacement/g;
write_file(q{filename.txt}, $s);
__END__
Or you could try the command-line arguments:
perl -ibak -pe"s/expr/repl/g" filename.txt
But you have to be careful with quoting the characters in the regex, etc.