my $regex=qr/^Device(\s)+Configuration/; ... my $result = $functions{$regex}->($var2);