I want to open a file, read it's contents line by line, perform a regex on each line, make a substitution if necessary, write it to the file, then close the file.
consider this bit of code:
use Tie::File;
use strict;
my @ry=();
# I'm not sure where $foo came from in your OP...
tie @ry,"Tie::File","$foo" or die "$foo -- $!";
$_ =~s/hello/goodbye/gi foreach @ry;
untie @ry;