package Pseudo::Tie::Scalar::Handle; use strict; use warnings; use Fcntl; use IO::File; sub new { my($class,$file) = @_; my $fh = IO::File->new($file,O_RDWR|O_CREAT); return unless defined $fh; bless { file => $file, handle => $fh, }, $class; } sub AUTOLOAD { no strict 'vars'; warn "$AUTOLOAD not implemented for a Pseudo::Tie::Scalar::Handle object\n"; } sub DESTROY {} sub substr ($$;$$) { my $self = shift; my $fh = $self->{handle}; seek $fh, shift, 0; my $size = shift; my $chunk; if (defined $size) { warn "substr replacement not implemented\n" if @_; read $fh, $chunk, $size; } else { $chunk = do { local $/; <$fh> } } return $chunk; } 1; package main; use strict; use warnings; my $pseudo_string = Pseudo::Tie::Scalar::Handle->new('/test.txt'); print "\nnot-working: ",substr $pseudo_string, 0, 43;