#!/usr/bin/perl -w use strict; use warnings; my $transactID = "item=" ; #### Usually a number my $itemname = "itemname" ; #### Usually alphanumeric my $quantity = "qty" ; #### Always numeric open(IN,'ItemsFile.rtf') or die("can't open input file\n"); open(OUT,'>results.txt') or die("can't open output file\n"); while(){ print OUT "0 ", substr($',3,17), "; " if($_ =~/\b$transactID\b/i); print OUT "1 ", substr($',2,12), "; " if($_ =~/\b$itemID\b/i); print OUT "2 ", substr($',13,3), "; " if($_ =~/\b$quantity\b/i); } close(IN); close(OUT);