/usr/bin/perl -w use strict; my $client = 123; # default value my $regx = qr/$client/; check_logs($regx); sub check_logs { my $regx = shift(@_); my @clients = qw(abc, def, hij); foreach my $client (@clients) { print($regx, "\n"); } # I want the $regex to bind to the $client variable inside the sub. }