# lib/Anti/Tidy.pm package Anti::Tidy; use overload # Overload Perl operations '""' => \&_stringify, ; sub new { return bless {}, shift }; sub _stringify { my $self = shift; for ( $self->{-string} ) { s/[\t\n]//gs; s/\\t/\t/g; s/\\n/\n/g; }; return $self; }; sub put_string { my $self = shift; $self->{-string} = shift; return $self; }; # bin/yourscript.pl use Anti::Tidy; my $uglyfruit = Anti::Tidy->new; $uglyfruit->put_string('Hideous \t big old string with embedded hard tabs and hard newlines to be ignored\n but with escape \t sequences to be \n expanded.'); say $uglyfruit;