#!/usr/bin/perl use strict; my @buf = ; for my $i ( 0 .. $#buf ) { if ($buf[$i] =~ s/^\s*(.*)<\/jobnumber>\s*$/$1/s) { $buf[$i+1] =~ s/^\s*\s*(.*)\s\s*$/$1/s; # if your tags are really like this &process($buf[$i],$buf[$i+1]); } } sub process { my ($jobnumber,$location) = @_; print "Found a job $jobnumber in $location.\n"; # do something } __DATA__ 1234 Somecity, NJ 87922 Othercity, AK