my @contents = $rw->read('file.txt'); for (@contents) { ... } $rw->write(contents => \@contents);