#!/usr/bin/perl -w use strict; my @items = qw (P40303 Q99436 X1234 W9765543); my $regex = join ("|",@items); print $regex; # to see what this does # put something like this in your "grep" # P40303|Q99436|X1234|W976554 while (<>) { print if m/$regex/; } __END__ Perl 5.10 is pretty smart. I think that the /o option is not necessary here. I don't think more complex syntax's are either.