#!/usr/bin/perl use strict; use warnings; my $data = 'pro my project con my customer date 2009-10-5 at 17:00 pri 2 msg Rack new server'; #pro = my project #con = my customer #date = 2009-10-5 #at = 17:00 #pri = 2 #msg = Rack new server my @keywords = qw(pro con due date at pri msg); # \b(pro|con|due|date|at|pri|msg)\s((?:(?!(pro|con|due|date|at|pri|msg)\b).)*) my $regex = '\b(' . join('|', @keywords) . ')\s((?:(?!(' . join('|', @keywords) . ')\b).)*)'; while ($data =~ /$regex/ig) { print "$1 = $2\n"; }