#!/usr/bin/perl use strict; use warnings; package RefReplacer; use overload '""' => \&replace; my $self; sub new{ my ($class,$string) = @_; $self = {}; bless $self,$class; $self->string($string); return $self; } sub string{ my ($self,$string) = @_; $self->{string} = $string if defined $string; return $self->{string}; } sub pattern{ my ($self,$pattern,$ref) = @_; $self->{pattern}->{$pattern} = $ref; } sub replace{ my $string = $self->string; for my $pat(keys %{$self->{pattern}}){ my $ref = $self->{pattern}->{$pat}; $string =~ s/$pat/$$ref/g; } return $string; } package main; my $foo = (); my $bar = \$foo; my $string = RefReplacer->new('hello <--REPLACE-->'); $string->pattern('<--REPLACE-->',\$foo); # das klappt natürlich nicht $foo = 'world'; print $string, "\n"; $foo = 'community'; print $string, "\n";