use strict; { package Foo; my $str = 'foo str'; sub str { my $class = shift; $str = $_[0] if @_; return $str; } } { package Bar; my $str = 'bar str'; sub str { my $class = shift; $str = $_[0] if @_; return $str; } } my $class = 'Foo'; my $value = $class->str();