use strict; use warnings; #### sub parse { my ($self,$hashref)=@_; open my $fh, '<:raw', $self->{FILE} or die $!; while (<$fh>) { chomp; $hashref->{$_}++ for split; } } #### #!/usr/bin/perl -l use strict; use warnings; package Foo; sub new { my ($self,$file)=@_; bless { FILE => $file }, $self; } sub parse { my ($self,$hashref)=@_; open my $fh, '<:raw', $self->{FILE} or die $!; while (<$fh>) { chomp; $hashref->{$_}++ for split; } } package main; my ($file,%hash)=shift; Foo->new($file)->parse(\%hash); # right Foo::parse(%hash); # wrong print for keys %hash; __END__