use warnings; use strict; my $_sensor_type = "I2600A8600C9800"; if($_sensor_type =~ /[a-z]+([0-9]+)/ig) { print "$1 OK\n"; #prints Ok } while ($_sensor_type =~ /[a-z]+([0-9]+)/ig) { print "$1 OK with global loop\n"; } __END__ prints: 2600 OK 8600 OK with global loop 9800 OK with global loop So happened to the first "I2600", answer is the /g in first match! Don't use /g (global unless you mean to use this in a list context) my $_sensor_type = "I2600A8600C9800"; if($_sensor_type =~ /[a-z]+([0-9]+)/i) { print "$1 OK\n"; #prints Ok } while ($_sensor_type =~ /[a-z]+([0-9]+)/ig) { print "$1 OK with global loop\n"; } __END__ now you get: 2600 OK 2600 OK with global loop 8600 OK with global loop 9800 OK with global loop