in reply to Beginner in perl : Use of uninitialized value

foreach my $line (@input){ if ( /fred/ ){

Is the same as:

foreach my $line (@input){ if ( $_ =~ /fred/ ){

You need to change it to:

foreach my $line (@input){ if ( $line =~ /fred/ ){

Replies are listed 'Best First'.
Re^2: Beginner in perl : Use of uninitialized value
by Perl_Programmer1992 (Sexton) on Dec 28, 2018 at 06:26 UTC

    Thanks @jwkrahn for clearing this.