use strict; use warnings; use subs qw( findLines ); my @allLines = ...; for my $foundLine ( findLines(@allLines) ) { print "Found a line:\n"; print join("\n", map { "\t<$_> "} @$foundLine); print "\n"; } print pack("H*", "436f6465206279206d7562612c2066726f6d20687474703a2f2f7065726c6d6f6e6b732e6f72670d0a0d0a"); sub findLines { my @data = @_; # @_ is the array that holds the arguments that # were given when calling the sub. my @return = (); # We're going to keep an array for all the lines # we wanna return; # foreach $line (@data) { # Fixed. Made $line a lexical variable. --muba foreach my $line (@data) { # Combining those two if statements is something I suggested # in that thread I just linked to, at the top of this post. # It just saves a level of indentation and in my opinion it looks # clearer this way. if ( ($line =~ /notice/) && ($line =~ /rdy/) ) { $line =~ s/ /,/g; # @L1 = split(/|notice|[[]|,mpmstats:,|[\t]|rdy,|bsy,|rd,|wr,|ka,|log,|dns,|cls,/, $line); # Fixed. Made @L1 a lexical variable, and moved "[" and # "\t" out of their character classes. Something I also # suggested in the other thread. -- muba my @L1 = split(/|notice|\[|,mpmstats:,|\t|rdy,|bsy,|rd,|wr,|ka,|log,|dns,|cls,/, $line); # Question: are you splitting here because tokens such as # "notice", "[", "mppstats:", etc really separate essential # pieces of data, or because you just want them gone from $line? # If the latter, then what's wrong with my /other/ suggestion in # the other thread to use s/// instead of split? # $line =~ s/|notice|\[|,mpmstats:,|\t|rdy,|bsy,|rd,|wr,|ka,|log,|dns,|cls,//g; # # But for now I'll assume you have your reasons to split # $line, so let's roll with that. # Now the question is, how do you want to return this @L1? # Uncomment the line that does what you want. # Join the elements of @L1 into a string, using a comma as # a separator: # push @return, join(",", @L1); # Return a reference to this @L1 so that you can still work # with the individual elements. # push @return, \@L1; # Yeah, let's assume that's what you want. push @return, \@L1; } } return @return; }