#!/usr/bin/perl -w use strict; #----------------------- package StringHandle; use overload '<>' => sub { return shift @{$_[0]}; }; sub new { my $class = shift; return bless [split /^/m, $_[0]], $class; } sub close { # does nothing. Just to emulate FileHandle }; #----------------------- package main; use FileHandle; my $param = shift; my $text = undef; if ($param) { $text = new FileHandle $param || die "can't open $param\n"; } else { $text = new StringHandle "aaa\nbbb\nccc\nddd\n" || die "can't create new handle\n"; } print while <$text>; # reads from either a file or a string $text->close;