use Modern::Perl; use Tie::File; my @tied_array; tie @tied_array, 'Tie::File', 'test.txt', autochomp => 1; s/\s+/,/g for @tied_array;