#!/usr/bin/perl -w use strict; my $string = "Field1: one"; my @regex; push(@regex, qr/Field1: (\w{3})/); push(@regex, qr/Field2: (\w{3})/); push(@regex, qr/Field3: (\w{3})/); foreach (@regex) { if ($string =~ $_ ) { print "$1\n"; } }