#!/usr/bin/perl -w use strict; use warnings; use IO::Dir; my $dh=bless {}, 'IO::Dir::pl'; #my $dh = IO::Dir::pl->new('.'); while (my $file_name = $dh->read()){ print STDOUT "$file_name\n"; exit; } { package IO::Dir::pl; use strict; use warnings; our @ISA; @ISA = qw(IO::Dir); sub read{ my $self = shift; warn "Ok We got here.\n"; return undef; } } > /tmp/p Ok We got here. (in cleanup) Not a GLOB reference at /usr/lib/perl5/5.16.2/x86_64-linux-thread-multi/IO/Dir.pm line 43.