package Book::HTML2TextConvertor; sub handler { my $r = shift; untie *STDOUT; tie *STDOUT => __PACKAGE__, $r; } sub TIEHANDLE { my($class, $r) = @_; bless { r => $r}, $class; } sub PRINT { my $self = shift; for (@_) { # copy it so no 'read-only value modification' will happen my $line = $_; $line =~ s/<[^>]*>//g; # strip the html $self->{r}->print($line); } } 1;