package LogMatch; sub new { my $class = shift; my %args = @_; my $self = {}; $self->{pre} = $args{pre} || 'PREdefault'; $self->{post} = $args{post} || 'POSTdefault'; $self->{term} = $args{term} || 'TERMdefault'; bless $self, $class; } sub search { my $self = shift; my $term = shift; $term = $self->{term} unless defined $term; return qr/$self->{pre}$term$self->{post}/; } 1; package main; my $s1 = LogMatch->new(pre=>'\d\d\d\d',post=>',',term=>'foo'); my $s2 = LogMatch->new; my @clients = qw( foo bar baz hazmat coz meat ); foreach my $client (@clients) { my $regex1 = $s1->search($client); my $regex2 = $s2->search($client); print "$regex1\t\t$regex2\n"; }