in reply to Re: Regular Expressions with varialbe with "[]"
in thread Regular Expressions with varialbe with "[]"

Thanks pme another method to solve , following is my code and what I want :

#!/usr/bin/perl use 5.010; use strict; use warnings; my $port_name = 'sdm_yout_i[1]'; $port_name =~ s/\[|\]/\\$&/g; # escaping &#91; and &#93; open my $fh, "tt.txt" or die $!; while (<$fh>) { if ( /\.([0-9a-z_]+?) \( \{.*?${port_name} .*?,/ ) { print '$port_name = ' ; say $port_name; print '$cell name = ' ; say $1; } }

Output :

$port_name = sdm_yout_i\[1\] $cell name = sdm_yout_i