in reply to Trying to read print in a loop inside a subroutine

Can someone tell me the mistake I am doing here?

Unlikely, because it isn't self-contained. You are reading 1 set of input from the INPUT_FILE handle (which I'm guessing corresponds to the sample input you have provided) and 2 other sets of input from the REPLAY_FILE handle which have not been provided to us. Without an SSCCE, the my best guess is that you don't really want a regex match at if ($rpl_sub =~ /^$line/) but rather a substring match.

See the Basic Debugging Checklist for how you can help yourself. Good luck.

Replies are listed 'Best First'.
Re^2: Trying to read print in a loop inside a subroutine
by kaushik9918 (Sexton) on May 20, 2020 at 12:32 UTC

    you are right, I am looking for

    if ($rpl_sub =~ /^$ip_var\|VALUE/)
    instead of   if ($rpl_sub =~ /^$line/)