#!/usr/bin/perl use strict; use warnings; my $ldif = "file.ldif.bz2"; my $match = "g2ucab"; $/ = ""; open my $fh, "-|", "/usr/bin/bzcat $ldif" or die "open error ($ldif): $!"; while ( <$fh> ) { if ( /uid=$match/m ) { print $_; last; } } close $fh;