Hold buffer in perl

Hi,

Can any one tell me is their any "hold buffer" in perl similar to sed.

I have to find a pattern, once that pattern found then need to go backward and find another pattern and print.

Example:

Below are the contents present in a file
##
block
IPs
URLs
URL_IPs
Unblock
URLs

Script should search for "Unblock" pattern first and then go backward and find the "block" pattern and print "block" and "Unblock" patterns.

I know it how to do in sed. But i want it in perl.

Thanks

What is the desired output for the input file you posted (repeated below) ?

##
block
IPs
URLs
URL_IPs
Unblock
URLs

tyler_durden

Sorry for the delay:

I want to search for Unblock first and then go back and find for "block" pattern

say content of file is:

block 2010.5
IPs
URLs
URL_IPs
URLs

block 2010.6
IPs
URLs
URL_IPs
Unblock
URLs

Check for "unblock" pattern, if "unblock" pattern is their, then go back(move to the previous lines) and search if "block" pattern is their. If block patten exist, then print the first "block" pattern.

Output should be: block 2010.6

---------- Post updated at 01:31 PM ---------- Previous update was at 01:00 PM ----------

Can any one please post answer quickly

there is no concept of hold buffer in perl. you cannot directly replace sed with perl... Learn perl RE basics such as substituion, default variables and back references.

No need to "go back". On your line-by-line sweep store the line when you find "block", then print what you stored when you encounter "Unblock".
In perl you have as many hold buffers as you need -- variables.