use IO::File (); use IO::Scalar (); sub do_stuff_with_a_fh { my ($fh) = @_; ...do stuff... } my $str = "this is my string"; my $fh_scalar = IO::Scalar->new(\$str) or die "failed to create fh from str: $!"; do_stuff_with_a_fh($fh_scalar); my $fh_stdin_duped = IO::File->new("<&STDIN") or die "failed to dup stdin: $!"; do_stuff_with_a_fh($fh_sdtin_duped);