if ($string =~ m{ (foo|bar) (\d+) (w[ia]g) }xms) { my ($one, $two, $three) = ($1, $2, $3); do_something_with($one); ... } #### if (my ($one, $two, $three) = $string =~ m{ (foo|bar) (\d+) (w[ia]g) }xms) { do_something_with($one); ... }