sub findtext { my ($fileargs, $inputs) = @_; # pass references to arrays my @filenames; for my $arg ( @$fileargs ) { # dereference this array push @filenames, grep /\w/, split( /\W+/, $arg ); } for my $file ( @filenames ) { unless open( FILE, "/home/jroberts/$file.txt" ) { warn "open failed on $file: $!"; next; } while () { for my $term ( @$inputs ) { # dereference this array next unless ( /\b$term\b/ ); # get here when there's a match... # (not sure what you want to do here) } } } }