#!/usr/bin/perl use 5.016; use strict; use warnings; # 1039350 $_ = " this is a number [12345] "; if(/^\s*(.+)\s*/){ say "in outter 'if', \$1: $1"; $_ = $1; if($1 =~ /\[(\d+)\]/){ say "\t But in inner if, \$1 : $1"; } } =head output: in outter 'if', $1: this is a number [12345] But in inner if, $1 : 12345 =cut