package Length; sub new { my ($class, $value, $unit) = @_; # Create $self and store the value in standard form. # In case of length this means converting the length to meters. } sub as_km { shift->{_m} / 1000 } sub as_hm { shift->{_m} / 100 } sub as_dam { shift->{_m} / 10 } sub as_m { shift->{_m} } sub as_dm { shift->{_m} * 10 } sub as_cm { shift->{_m} * 100 } sub as_mm { shift->{_m} * 1000 } # Or, if this were really something I made, just: sub as { my ($self, $unit) = @_; # ... }