open my $memFH, '+>', \my $buffer; $object->cat( $memFH, $target ); while( <$fh> ) { ## do something with it } # Or $buffer =~ s[...][...]mg; #etc