my @strings = ( ...); for my $digit (@strings) { $digit =~ s/^--\s(\d+)\s-*$/$1/; # do sth with $digit }