$chapter =~ s/\D+//g; # remove all non-digit characters # or perhaps to avoid the /g flag, (I wouldn't code it this way # because it is overly complex) however: $chapter =~ s/^(\D*)(\d+)(\D*)/$2/; # remove all optional non-digit stuff # before or after the digits # try the above with "XX546YYY", just "453ZZ" and "AAA123ZZZ77548" as # cases to probe the limits... what happens if it is not just "11VI"? #### my $x = "3"; if ($x > 3){...} #### my $x = "chapter 5"; print "chap 5 ok!" if $x == 5; # Throws Warning: Argument "chapter 5" isn't numeric in numeric eq (==) $x =~ s/\D+//g; # eliminate all non 0-9 characters from string print "chap 5 ok!" if $x == 5; # chapter 5 is ok now! # The string got "fixed" to be completely numeric # Then when Perl made it into binary number to compare against 5, it worked! #### $x = "00005"; print "$x\n"; #yields "00005" $x += 0; #adding zero forces numeric conversion print "$x\n"; #yields "5"