my $user = $2 if $remainder =~ m/ user= (\W?) # possible one non-word character ([\w\-.@]+) # word characters and -.@ # there should be a way to improve it, # some kind of [^\g1] \g1 /x;