use strict; my $correctanswer = "11408"; my $regexp = qr/^([\d]+)*(hullBts_static)/; while () { if ( /$regexp/ ) { if ( $1 eq $correctanswer ) { print( "Congratulations, the regexp is correct!" ); exit( 1 ); } else { die( "Error, match was $1" ) } } } die( "Error, never matched" ); __DATA__ 11299 pts/4 00:00:00 su 11303 pts/4 00:00:00 bash 11403 tty2 00:00:00 bsc_static 11406 tty2 00:00:00 rtpTrau_static 11408 tty2 00:11:30 hullBts_static 11418 pts/4 00:00:00 tail 12157 pts/5 00:00:00 su