Hi, You can try the below pattern.
if($line=~/([0-9]{3,})/gs) { print $1; } Thanks, Vijaya ------------------------------ From: punit jain Sent: 12/11/2013 9:07 PM To: beginners@perl.org Subject: Regex not working correctly Hi, I have a requirement where I need to capture phone number from different strings. The strings could be :- 1. COMP TEL NO 919369721113 for computer science 2. For Best Discount reach 092108493, from 6-9 3. Your booking Confirmed, 9210833321 4. price for free consultation call92504060 5. price for free consultation call92504060number I created a regex as below :- #!/usr/bin/perl my $line= shift @ARGV; if($line =~ /(?:(?:\D+|\s+)(?:(91\d{10}|0\d{10}|[7-9]\d{9}|0\d{11})|(?:(?:ph|cal)(\d+))))|(?:(?:(91\d{10}|0\d{10}|[7-9]\d{9}|0\d{11})|(?:(?:ph|cal)(\d+)))(?:\D+|\s+))/) { print "one = $1"; } It works fine for 1, 2,3 and prints number however for 4 and 5 one I get number in $2 rather than $1 tough I have pipe operator to check it. Any clue how to fix this ?