How to get lines having a variable in perl?

Hi, This might be simple question. But i couldn't find the answer.
#$ra is having a value which i have got from some other file
I want the first occurrence of the line having the value that is in variable "$ra"
This is what i have tried.

while ( $iop = <TST>)
{
  if($iop =~ /$ra/)
{
  print "$iop \n";
  last;
  }
}

plz help me.
Thanks in advance

Must the two lines be identical (in which place you should probably chomp and perform an eq comparison rather than use a regex...)

putting $ra_r=qr($ra); outside the loop and then checking if $iop=~$ra_r would speed up the code slightly (only one regex compilation.

What issue are you seeing?

the vaule of $ra=000000000000096C

Now i want the first line of a file that is having the value 000000000000096C
for example:

I 000000000000096C 48000000  * 000000000000096C         b         *

Here is the new code i wrote

33: # printing the iop corresponding to real address
34: open (TST, '<psi.tst');
35: while ( $iop = <TST>)
36: {
37:   if($iop =~ /$ra/){
38:     last;
39:  }
40:  }
41:  print $iop;

ERROR iam getting is :

Use of uninitialized value in print at psi.pl line 41, <TST> line 51574.

Hi,

try this:

INPUT

hi
line2 has 000000000000096C
line3 is here.

line 5 also has 000000000000096C
line3 twice.
#!/usr/bin/perl -w
use 5.010;
my $ra="000000000000096C";
say "INPUT IS:$ra";

while (<>){
chomp;
if ( /$ra/ ) {
say;
last;
}
}

HI greet_sed

iam getting some different errors when i tried your code.

Unquoted string "say" may clash with future reserved word at temp2.pl line 9.
No such class say at temp2.pl line 4, near "my say"
syntax error at temp2.pl line 4, near "my say "INPUT IS:$ra""
Execution of temp2.pl aborted due to compilation errors.

Did you add use 5.010 line in your code?

Use print instead of say to avoid errors.

for ex:

print "$ra\n";
print;

Thanks, i got it where i missed. I just did chomp of the variable. Now its working. I think when i extracted $ra new line character also came. So i removed it. It took almost 4 hours for to do experiments & figure out.

$ra = substr ($lastword,$n);
print "$lastword";
print "$ra";
chomp($ra);
# printing the iop corresponding to real address
open (TST, '<psi.txt');

while ( $iop = <TST>)
{ # chomp;
  if( $iop =~ /$ra/ ){
      print "$iop";
      last;
  }
}