use strict; use Data::Dumper; my @txtfile=("file/path - skipped", "file/path - cannot verify", "file/path - corrupt file", "My camel has fleas", ); my @regex=('\bcannot verify', '\bcorrupt file', '\bskipped', ); my @outfile; foreach my $error (@txtfile) { foreach (@regex) { push (@outfile, $error) if $error=~/$_/; } } print Dumper(\@outfile); __END__ $VAR1 = [ 'file/path - skipped', 'file/path - cannot verify', 'file/path - corrupt file' ];