my @matches = ( $str =~ /pa(tt)ern/g )
perl -le '@m = ( "foo12gfd2bgbg654" =~ /(\d+)/g ); print for @m'
12 2 654